From 393e5c9303376ac5e4cc594cb5ecf35555f71079 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 5 May 2019 09:48:20 -0400 Subject: [PATCH] IfExp precidence handling in 2.6... 2.7 still has a bug --- test/bytecode_2.6_run/04_ifelse_parens.pyc | Bin 0 -> 473 bytes test/simple_source/bug26/04_ifelse_parens.py | 9 +++++++++ uncompyle6/semantics/consts.py | 10 ++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 test/bytecode_2.6_run/04_ifelse_parens.pyc create mode 100644 test/simple_source/bug26/04_ifelse_parens.py 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 0000000000000000000000000000000000000000..adcb710a6779eda29fa485fa62a8754490e3891c GIT binary patch literal 473 zcmb7AF;2rk5S+6OBp@jG1TGK(gs37EM4(IoR6t}I`ntDxC10>50amcRA3h1O{^H#`dE0V zHXv+(R{_D zUIbbnjZb-xLX+HSht7n~>{Tg4SJ-tzmdheF-H+)0XlmV9*0mY=kR3WOd#p^ptO^+! zRqI3!9_!ih>EQ4r$}?FQ8C9{Cr8%gcZJ)EzJT~(vPE+?-#`!^vMD8v;2_1Lcf#W;7 sTU|@*sH>P_c8AruF;d%Hm6uv8{kO~i7wS=MxKwFf$g^%A_b~n77qWU;ZU6uP literal 0 HcmV?d00001 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 ),