You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Adjust 3.7 chained compare for adjusted grammar
Add test for last change
This commit is contained in:
BIN
test/bytecode_3.7_run/01_if_and_if_bug.pyc
Normal file
BIN
test/bytecode_3.7_run/01_if_and_if_bug.pyc
Normal file
Binary file not shown.
16
test/simple_source/bug36/01_if_and_if_bug.py
Normal file
16
test/simple_source/bug36/01_if_and_if_bug.py
Normal file
@@ -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
|
@@ -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
|
# 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
|
# 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_chained1a_37
|
||||||
compare_chained37 ::= expr compare_chained1b_37
|
compare_chained37 ::= expr compare_chained1b_37
|
||||||
compare_chained2a_37 ::= expr COMPARE_OP POP_JUMP_IF_TRUE JUMP_FORWARD
|
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_chained1a_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
||||||
compare_chained2a_37 ELSE POP_TOP COME_FROM
|
compare_chained2a_37 ELSE POP_TOP COME_FROM
|
||||||
compare_chained1b_37 ::= expr DUP_TOP ROT_THREE COMPARE_OP POP_JUMP_IF_FALSE
|
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):
|
def customize_grammar_rules(self, tokens, customize):
|
||||||
|
@@ -922,7 +922,7 @@ def customize_for_version3(self, version):
|
|||||||
(-4, 19)),
|
(-4, 19)),
|
||||||
'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p',
|
'compare_chained1b_37': ( ' %[3]{pattr.replace("-", " ")} %p %p',
|
||||||
(0, 19),
|
(0, 19),
|
||||||
(-5, 19)),
|
(-4, 19)),
|
||||||
'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
'compare_chained2a_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
||||||
|
|
||||||
'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
'compare_chained2b_37': ( '%[1]{pattr.replace("-", " ")} %p', (0, 19)),
|
||||||
|
Reference in New Issue
Block a user