diff --git a/test/bytecode_2.6_run/04_ifelse_parens.pyc b/test/bytecode_2.6_run/04_ifelse_parens.pyc new file mode 100644 index 00000000..adcb710a Binary files /dev/null and b/test/bytecode_2.6_run/04_ifelse_parens.pyc differ diff --git a/test/simple_source/bug26/04_ifelse_parens.py b/test/simple_source/bug26/04_ifelse_parens.py new file mode 100644 index 00000000..00c4129b --- /dev/null +++ b/test/simple_source/bug26/04_ifelse_parens.py @@ -0,0 +1,9 @@ +# From 3.7.3 dataclasses.py +# Bug was handling precedence. Need parenthesis before IfExp. +# +# RUNNABLE! +def _hash_add(fields): + flds = [f for f in fields if (4 if f is None else f)] + return flds + +assert _hash_add([None, True, False, 3]) == [None, True, 3] diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 4ffd34c0..b90ad958 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -95,6 +95,7 @@ PRECEDENCE = { 'conditional_lamdba': 28, 'conditional_not_lamdba': 28, 'conditionalnot': 28, + 'conditional_true': 28, 'ret_cond': 28, '_mklambda': 30, @@ -257,10 +258,11 @@ TABLE_DIRECT = { 'list_iter': ( '%c', 0 ), 'list_for': ( ' for %c in %c%c', 2, 0, 3 ), - 'list_if': ( ' if %c%c', 0, 2 ), - 'list_if_not': ( ' if not %p%c', - (0, 'expr', PRECEDENCE['unary_not']), - 2 ), + 'list_if': ( ' if %p%c', + (0, 'expr', 27), 2 ), + 'list_if_not': ( ' if not %p%c', + (0, 'expr', PRECEDENCE['unary_not']), + 2 ), 'lc_body': ( '', ), # ignore when recursing 'comp_iter': ( '%c', 0 ),