diff --git a/test/bytecode_3.0_run/06_listcomp.pyc b/test/bytecode_3.0_run/06_listcomp.pyc index d21e8451..90799847 100644 Binary files a/test/bytecode_3.0_run/06_listcomp.pyc and b/test/bytecode_3.0_run/06_listcomp.pyc differ diff --git a/test/simple_source/bug30/06_listcomp.py b/test/simple_source/bug30/06_listcomp.py new file mode 100644 index 00000000..5ee9c295 --- /dev/null +++ b/test/simple_source/bug30/06_listcomp.py @@ -0,0 +1,24 @@ +# Python 3.0 comprehensions can produce different code from +# all other Python versions. Thanks, Python! + +# This code is RUNNABLE! + +# Adapted from 3.0 ast.py; uses comprehension implemented via CLOSURE +def _format(node): + return [(a, int(b)) for a, b in node.items()] + +x = {'a': '1', 'b': '2'} +assert [('a', 1), ('b', 2)] == _format(x) + +# Adapted from 3.0 cmd.py; ises "if" comprehension +def monthrange(ary, dotext): + return [a[3:] for a in ary if a.startswith(dotext)] + +ary = ["Monday", "Twoday", "Monmonth"] +assert ['day', 'month'] == monthrange(ary, "Mon") + +# From 3.0 cmd.py; uses "if not" comprehension +def columnize(l): + return [i for i in range(len(l)) + if not isinstance(l[i], str)] +assert [0, 2] == columnize([1, 'a', 2]) diff --git a/uncompyle6/parsers/parse30.py b/uncompyle6/parsers/parse30.py index 1c1f2c70..d7f7a60a 100644 --- a/uncompyle6/parsers/parse30.py +++ b/uncompyle6/parsers/parse30.py @@ -62,6 +62,7 @@ class Python30Parser(Python31Parser): # JUMP_IF_TRUE POP_TOP as a replacement comp_if ::= expr jmp_false comp_iter comp_if ::= expr jmp_false comp_iter JUMP_BACK POP_TOP + comp_if_not ::= expr jmp_true comp_iter JUMP_BACK POP_TOP comp_iter ::= expr expr SET_ADD comp_iter ::= expr expr LIST_APPEND