From 4a354269bcb685837ba0a3adec2668be2952e53f Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 23 Mar 2019 17:06:50 -0400 Subject: [PATCH] Adjust 3.7 chained compare for adjusted grammar Add test for last change --- test/bytecode_3.7_run/01_if_and_if_bug.pyc | Bin 0 -> 394 bytes test/simple_source/bug36/01_if_and_if_bug.py | 16 ++++++++++++++++ uncompyle6/parsers/parse37.py | 6 +++--- uncompyle6/semantics/customize3.py | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 test/bytecode_3.7_run/01_if_and_if_bug.pyc create mode 100644 test/simple_source/bug36/01_if_and_if_bug.py diff --git a/test/bytecode_3.7_run/01_if_and_if_bug.pyc b/test/bytecode_3.7_run/01_if_and_if_bug.pyc new file mode 100644 index 0000000000000000000000000000000000000000..45c20edeff7b951c2a8163148c564485a45f1daa GIT binary patch literal 394 zcmYk2Jx;?w5QS%UP1qpfiV7iGl!gQ$Q6a={3W_vPAQZ_;ybf3-b~GDHAUO?ihTMUJ zaEWcHas?`83}oCHw5mJ)L-vMX5+%`)I6qZP##hK1{ z-b|N@Hm&Ae^Ua{U5c@)j$dET?9{U~#9%GM>Boiz7+;Qo6GD;$s7ZfM0L2Y5~_Ly}68+HI=pg%3}hOK6(r*#%Kff5G3U WI(xl29Ot$eB}Y|&VPxtXDE$T1(@rS> literal 0 HcmV?d00001 diff --git a/test/simple_source/bug36/01_if_and_if_bug.py b/test/simple_source/bug36/01_if_and_if_bug.py new file mode 100644 index 00000000..9a529595 --- /dev/null +++ b/test/simple_source/bug36/01_if_and_if_bug.py @@ -0,0 +1,16 @@ +# Bug in 3.6 was not taking "else" branch after compond "if" +# In earlier versions we had else detection needed here. + +def f(a, b, c): + if a and b: + x = 1 + else: + x = 2 + if c: + x = 3 + return(x) + +assert f(True, True, True) == 3 +assert f(True, True, False) == 1 +assert f(True, False, True) == 3 +assert f(True, False, False) == 2 diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 8e497c6c..0ba2c93b 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017-2018 Rocky Bernstein +# Copyright (c) 2017-2019 Rocky Bernstein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -73,11 +73,11 @@ class Python37Parser(Python36Parser): compare_chained37 ::= expr compare_chained1a_37 compare_chained37 ::= expr compare_chained1b_37 compare_chained2a_37 ::= expr COMPARE_OP POP_JUMP_IF_TRUE JUMP_FORWARD - compare_chained2b_37 ::= expr COMPARE_OP POP_JUMP_IF_FALSE JUMP_FORWARD + compare_chained2b_37 ::= expr COMPARE_OP COME_FROM POP_JUMP_IF_FALSE JUMP_FORWARD ELSE compare_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE compare_chained2a_37 ELSE POP_TOP COME_FROM compare_chained1b_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE - compare_chained2b_37 ELSE POP_TOP JUMP_FORWARD COME_FROM + compare_chained2b_37 POP_TOP JUMP_FORWARD COME_FROM """ def customize_grammar_rules(self, tokens, customize): diff --git a/uncompyle6/semantics/customize3.py b/uncompyle6/semantics/customize3.py index 5dce03f7..d8fa1200 100644 --- a/uncompyle6/semantics/customize3.py +++ b/uncompyle6/semantics/customize3.py @@ -922,7 +922,7 @@ def customize_for_version3(self, version): (-4, 19)), 'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p', (0, 19), - (-5, 19)), + (-4, 19)), 'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)), 'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),