Add tests, comment what's up with change..

and use isinstance()
This commit is contained in:
rocky
2021-12-31 11:27:15 -05:00
parent 9172f82bae
commit 203139eafa
5 changed files with 20 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,18 @@
"""This program is self-checking!"""
# Python 2.4 - 2.7 bug in transforming "else if" to "elif" in Python 2.4 .. 2.7
# From Issue #377
# RUNNABLE!
def loop_continue_dead_code(slots):
for name in slots:
if name:
pass
else:
continue
# The below is dead code
if x:
y()
else:
z()
loop_continue_dead_code([None, 1])

View File

@@ -293,7 +293,8 @@ class TreeTransform(GenericASTTraversal, object):
else_suite_index = 1
len_n = len(n)
if len_n == 1 and type(n[0]) is SyntaxTree and len(n[0]) == 1 and n[0] == "stmt":
# Sometimes stmt is reduced away and n[0] can be a single reduction like continue -> CONTINUE.
if len_n == 1 and isinstance(n[0], SyntaxTree) and len(n[0]) == 1 and n[0] == "stmt":
n = n[0][0]
elif len_n == 0:
return node