You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Refine 2.7 dead code test ..
in a hacky way. Will probalby have to expand this in the future or better do dead code analysis
This commit is contained in:
9
test/simple_source/bug27+/03_not_dead_code.py
Normal file
9
test/simple_source/bug27+/03_not_dead_code.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# Bug found in 2.7 test_itertools.py
|
||||
# Bug was erroneously using reduction to unconditional_true
|
||||
# A proper fix would be to use unconditional_true only when we
|
||||
# can determine there is or was dead code.
|
||||
from itertools import izip_longest
|
||||
for args in [['abc', range(6)]]:
|
||||
target = [tuple([arg[i] if i < len(arg) else None for arg in args])
|
||||
for i in range(max(map(len, args)))]
|
||||
assert list(izip_longest(*args)) == target
|
@@ -77,7 +77,6 @@ case $PYVERSION in
|
||||
[test_grammar.py]=1 # Too many stmts. Handle large stmts
|
||||
[test_io.py]=1 # Test takes too long to run
|
||||
[test_ioctl.py]=1 # Test takes too long to run
|
||||
[test_itertools.py]=1 # Syntax error - look at!
|
||||
[test_memoryio.py]=1 # FIX
|
||||
[test_multiprocessing.py]=1 # On uncompyle2, taks 24 secs
|
||||
[test_pep352.py]=1 # ?
|
||||
|
@@ -102,7 +102,9 @@ class Python27Parser(Python2Parser):
|
||||
|
||||
# conditional_true are for conditions which always evaluate true
|
||||
# There is dead or non-optional remnants of the condition code though,
|
||||
# and we use that to match on to reconstruct the source more accurately
|
||||
# and we use that to match on to reconstruct the source more accurately.
|
||||
# FIXME: we should do analysis and reduce *only* if there is dead code
|
||||
|
||||
expr ::= conditional_true
|
||||
conditional_true ::= expr JUMP_FORWARD expr COME_FROM
|
||||
|
||||
@@ -167,6 +169,7 @@ class Python27Parser(Python2Parser):
|
||||
""")
|
||||
super(Python27Parser, self).customize_grammar_rules(tokens, customize)
|
||||
self.check_reduce['and'] = 'AST'
|
||||
self.check_reduce['conditional_true'] = 'AST'
|
||||
return
|
||||
|
||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||
@@ -182,6 +185,15 @@ class Python27Parser(Python2Parser):
|
||||
jmp_target = jmp_false.offset + jmp_false.attr + 3
|
||||
return not (jmp_target == tokens[last].offset or
|
||||
tokens[last].pattr == jmp_false.pattr)
|
||||
elif rule[0] == ('conditional_true'):
|
||||
# FIXME: the below is a hack. script is probably never used in a boolean
|
||||
# What we really need is to look for precence of dead code.
|
||||
if ast[0] == 'expr':
|
||||
a = ast[0]
|
||||
else:
|
||||
a = ast
|
||||
return a[0] == 'subscript'
|
||||
|
||||
return False
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user