You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Better assert and AssertionError determine for Python 2.7
This commit is contained in:
@@ -533,14 +533,11 @@ class Python2Parser(PythonParser):
|
|||||||
# Dead code testing...
|
# Dead code testing...
|
||||||
# if lhs == 'while1elsestmt':
|
# if lhs == 'while1elsestmt':
|
||||||
# from trepan.api import debug; debug()
|
# from trepan.api import debug; debug()
|
||||||
|
|
||||||
if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] in ('and', 'or'):
|
if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] in ('and', 'or'):
|
||||||
return True
|
return True
|
||||||
elif lhs in ('raise_stmt1',):
|
elif lhs in ('raise_stmt1',):
|
||||||
# We will assme 'LOAD_ASSERT' will be handled by an assert grammar rule
|
# We will assume 'LOAD_ASSERT' will be handled by an assert grammar rule
|
||||||
return (tokens[first] == 'LOAD_ASSERT' and
|
return (tokens[first] == 'LOAD_ASSERT' and (last >= len(tokens)))
|
||||||
(last >= len(tokens) or tokens[last] not in
|
|
||||||
('COME_FROM', 'JUMP_BACK','JUMP_FORWARD')))
|
|
||||||
elif rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')):
|
elif rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')):
|
||||||
expr2 = ast[2]
|
expr2 = ast[2]
|
||||||
return expr2 == 'expr' and expr2[0] == 'LOAD_ASSERT'
|
return expr2 == 'expr' and expr2[0] == 'LOAD_ASSERT'
|
||||||
|
@@ -208,6 +208,8 @@ class Python27Parser(Python2Parser):
|
|||||||
self.check_reduce['and'] = 'AST'
|
self.check_reduce['and'] = 'AST'
|
||||||
# self.check_reduce['or'] = 'AST'
|
# self.check_reduce['or'] = 'AST'
|
||||||
self.check_reduce['raise_stmt1'] = 'AST'
|
self.check_reduce['raise_stmt1'] = 'AST'
|
||||||
|
self.check_reduce['assert'] = 'AST'
|
||||||
|
self.check_reduce['assert2'] = 'AST'
|
||||||
self.check_reduce['list_if_not'] = 'AST'
|
self.check_reduce['list_if_not'] = 'AST'
|
||||||
self.check_reduce['list_if'] = 'AST'
|
self.check_reduce['list_if'] = 'AST'
|
||||||
self.check_reduce['conditional_true'] = 'AST'
|
self.check_reduce['conditional_true'] = 'AST'
|
||||||
@@ -228,6 +230,10 @@ class Python27Parser(Python2Parser):
|
|||||||
tokens[last].pattr == jmp_false.pattr)
|
tokens[last].pattr == jmp_false.pattr)
|
||||||
elif rule[0] == ('raise_stmt1'):
|
elif rule[0] == ('raise_stmt1'):
|
||||||
return ast[0] == 'expr' and ast[0][0] == 'or'
|
return ast[0] == 'expr' and ast[0][0] == 'or'
|
||||||
|
elif rule[0] in ('assert', 'assert2'):
|
||||||
|
jump_inst = ast[1][0]
|
||||||
|
jump_target = jump_inst.attr
|
||||||
|
return not (last >= len(tokens) or jump_target == tokens[last].offset)
|
||||||
elif rule == ('list_if_not', ('expr', 'jmp_true', 'list_iter')):
|
elif rule == ('list_if_not', ('expr', 'jmp_true', 'list_iter')):
|
||||||
jump_inst = ast[1][0]
|
jump_inst = ast[1][0]
|
||||||
jump_offset = jump_inst.attr
|
jump_offset = jump_inst.attr
|
||||||
|
Reference in New Issue
Block a user