You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
BIN
test/bytecode_3.7_run/00_if_elif.pyc
Normal file
BIN
test/bytecode_3.7_run/00_if_elif.pyc
Normal file
Binary file not shown.
15
test/simple_source/bug36/00_if_elif.py
Normal file
15
test/simple_source/bug36/00_if_elif.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Python 3 bug in not detecting the end bounds of if elif.
|
||||||
|
def testit(b):
|
||||||
|
if b == 1:
|
||||||
|
a = 1
|
||||||
|
elif b == 2:
|
||||||
|
a = 2
|
||||||
|
else:
|
||||||
|
a = 4
|
||||||
|
|
||||||
|
return a
|
||||||
|
|
||||||
|
for x in (1, 2, 4):
|
||||||
|
x = testit(x)
|
||||||
|
assert x is not None, "Should have returned a value, not None"
|
||||||
|
assert x == x
|
@@ -26,6 +26,7 @@ If we succeed in creating a parse tree, then we have a Python program
|
|||||||
that a later phase can turn into a sequence of ASCII text.
|
that a later phase can turn into a sequence of ASCII text.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from uncompyle6.scanners.tok import Token
|
||||||
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
||||||
from uncompyle6.parsers.treenode import SyntaxTree
|
from uncompyle6.parsers.treenode import SyntaxTree
|
||||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
@@ -1136,6 +1137,7 @@ class Python3Parser(PythonParser):
|
|||||||
self.check_reduce['aug_assign2'] = 'AST'
|
self.check_reduce['aug_assign2'] = 'AST'
|
||||||
self.check_reduce['while1stmt'] = 'noAST'
|
self.check_reduce['while1stmt'] = 'noAST'
|
||||||
self.check_reduce['while1elsestmt'] = 'noAST'
|
self.check_reduce['while1elsestmt'] = 'noAST'
|
||||||
|
self.check_reduce['ifelsestmt'] = 'AST'
|
||||||
self.check_reduce['annotate_tuple'] = 'noAST'
|
self.check_reduce['annotate_tuple'] = 'noAST'
|
||||||
self.check_reduce['kwarg'] = 'noAST'
|
self.check_reduce['kwarg'] = 'noAST'
|
||||||
# FIXME: remove parser errors caused by the below
|
# FIXME: remove parser errors caused by the below
|
||||||
@@ -1212,6 +1214,14 @@ class Python3Parser(PythonParser):
|
|||||||
if offset != tokens[first].attr:
|
if offset != tokens[first].attr:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
elif rule == ('ifelsestmt',
|
||||||
|
('testexpr', 'c_stmts_opt', 'jump_forward_else', 'else_suite', '_come_froms')):
|
||||||
|
# Make sure the highest/smallest "come from" offset comes inside the "if".
|
||||||
|
come_froms = ast[-1]
|
||||||
|
if not isinstance(come_froms, Token):
|
||||||
|
return tokens[first].offset > come_froms[-1].attr
|
||||||
|
return False
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class Python30Parser(Python3Parser):
|
class Python30Parser(Python3Parser):
|
||||||
|
Reference in New Issue
Block a user