diff --git a/test/bytecode_2.6_run/01_ifelse_listcomp.pyc b/test/bytecode_2.6_run/01_ifelse_listcomp.pyc index efe324ab..7bba8d75 100644 Binary files a/test/bytecode_2.6_run/01_ifelse_listcomp.pyc and b/test/bytecode_2.6_run/01_ifelse_listcomp.pyc differ diff --git a/test/bytecode_2.7_run/01_ifelse_listcomp.pyc b/test/bytecode_2.7_run/01_ifelse_listcomp.pyc index b110fca9..359f5046 100644 Binary files a/test/bytecode_2.7_run/01_ifelse_listcomp.pyc and b/test/bytecode_2.7_run/01_ifelse_listcomp.pyc differ diff --git a/test/simple_source/bug26/01_ifelse_listcomp.py b/test/simple_source/bug26/01_ifelse_listcomp.py index efedeb63..3973c451 100644 --- a/test/simple_source/bug26/01_ifelse_listcomp.py +++ b/test/simple_source/bug26/01_ifelse_listcomp.py @@ -2,3 +2,10 @@ # This is RUNNABLE! assert [False, True, True, True, True] == [False if not a else True for a in range(5)] assert [True, False, False, False, False] == [False if a else True for a in range(5)] + +# From bug #225 +m = ['hi', 'he', 'ih', 'who', 'ho'] +ms = {} +for f in (f for f in m if f.startswith('h')): + ms[f] = 5 +assert ms == {'hi': 5, 'he': 5, 'ho': 5} diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index e9c176d3..b3228e35 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -229,6 +229,12 @@ class Python27Parser(Python2Parser): return invalid if rule == ('and', ('expr', 'jmp_false', 'expr', '\\e_come_from_opt')): + # If the instruction after the instructions formin "and" is an "YIELD_VALUE" + # then this is probably an "if" inside a comprehension. + if tokens[last] == 'YIELD_VALUE': + # Note: We might also consider testing last+1 being "POP_TOP" + return True + # Test that jmp_false jumps to the end of "and" # or that it jumps to the same place as the end of "and" jmp_false = ast[1][0]