You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Fix bug in Python 3 lambda expression handling
Some other small cleanup changes
This commit is contained in:
BIN
test/bytecode_3.5/05_lambda.pyc
Normal file
BIN
test/bytecode_3.5/05_lambda.pyc
Normal file
Binary file not shown.
10
test/simple_source/expression/05_lambda.py
Normal file
10
test/simple_source/expression/05_lambda.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Bug in Python 3
|
||||||
|
|
||||||
|
# mklambda ::= LOAD_LAMBDA LOAD_CONST MAKE_FUNCTION_0
|
||||||
|
# _mklambda ::= mklambda
|
||||||
|
# expr ::= _mklambda
|
||||||
|
# kwarg ::= LOAD_CONST expr
|
||||||
|
# exprlist ::= exprlist expr
|
||||||
|
# call_function ::= expr kwarg CALL_FUNCTION_256
|
||||||
|
|
||||||
|
inspect.formatargvalues(formatvalue=lambda value: __file__)
|
@@ -5,10 +5,10 @@ test_pyenvlib -- uncompyle and verify Python libraries
|
|||||||
|
|
||||||
Usage-Examples:
|
Usage-Examples:
|
||||||
|
|
||||||
test_pyenvlib --all # decompile all tests (suite + libs)
|
test_pyenvlib.py --all # decompile all tests (suite + libs)
|
||||||
test_pyenvlib --all --verify # decomyile all tests and verify results
|
test_pyenvlib.py --all --verify # decomyile all tests and verify results
|
||||||
test_pyenvlib --test # decompile only the testsuite
|
test_pyenvlib.py --test # decompile only the testsuite
|
||||||
test_pyenvlib --2.2 --verify # decompile and verify python lib 2.2
|
test_pyenvlib.py --2.7.11 --verify # decompile and verify python lib 2.7.11
|
||||||
|
|
||||||
Adding own test-trees:
|
Adding own test-trees:
|
||||||
|
|
||||||
|
@@ -524,8 +524,9 @@ class Python3Parser(PythonParser):
|
|||||||
rule = 'unpack_list ::= ' + opname + ' designator' * token.attr
|
rule = 'unpack_list ::= ' + opname + ' designator' * token.attr
|
||||||
elif opname_base.startswith('MAKE_FUNCTION'):
|
elif opname_base.startswith('MAKE_FUNCTION'):
|
||||||
args_pos, args_kw, annotate_args = token.attr
|
args_pos, args_kw, annotate_args = token.attr
|
||||||
self.addRule('mklambda ::= %sLOAD_LAMBDA %s' %
|
rule = ('mklambda ::= %sLOAD_LAMBDA LOAD_CONST %s' %
|
||||||
('pos_arg ' * args_pos, opname), nop_func)
|
('pos_arg '* args_pos, opname))
|
||||||
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
if self.version > 3.2:
|
if self.version > 3.2:
|
||||||
rule = ('mkfunc ::= %skwargs %s %s' %
|
rule = ('mkfunc ::= %skwargs %s %s' %
|
||||||
('pos_arg ' * args_pos,
|
('pos_arg ' * args_pos,
|
||||||
|
@@ -43,12 +43,15 @@ class Scanner3(scan.Scanner):
|
|||||||
## FIXME opnames should be passed in here
|
## FIXME opnames should be passed in here
|
||||||
def __init__(self, version):
|
def __init__(self, version):
|
||||||
self.version = version
|
self.version = version
|
||||||
|
self.opnames = {} # will eventually get passed in
|
||||||
scan.Scanner.__init__(self, version)
|
scan.Scanner.__init__(self, version)
|
||||||
|
|
||||||
|
|
||||||
## FIXME opnames should be moved to init
|
## FIXME opnames should be moved to init
|
||||||
def disassemble3(self, co, opnames, classname=None, code_objects={}):
|
def disassemble3(self, co, opnames, classname=None, code_objects={}):
|
||||||
|
|
||||||
|
self.opnames = opnames # will eventually disasppear
|
||||||
|
|
||||||
# import dis; dis.disassemble(co) # DEBUG
|
# import dis; dis.disassemble(co) # DEBUG
|
||||||
|
|
||||||
# Container for tokens
|
# Container for tokens
|
||||||
@@ -829,7 +832,9 @@ class Scanner3(scan.Scanner):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import inspect
|
import inspect
|
||||||
co = inspect.currentframe().f_code
|
co = inspect.currentframe().f_code
|
||||||
tokens, customize = Scanner3().disassemble_generic(co)
|
from uncompyle6 import PYTHON_VERSION
|
||||||
|
from opcode import opname
|
||||||
|
tokens, customize = Scanner3(PYTHON_VERSION).disassemble3(co, opname)
|
||||||
for t in tokens:
|
for t in tokens:
|
||||||
print(t)
|
print(t)
|
||||||
pass
|
pass
|
||||||
|
@@ -1605,7 +1605,10 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
pos_args = args_node.attr
|
pos_args = args_node.attr
|
||||||
pass
|
pass
|
||||||
|
|
||||||
code = node[code_index].attr
|
if self.version > 3.0 and isLambda and iscode(node[-3].attr):
|
||||||
|
code = node[-3].attr
|
||||||
|
else:
|
||||||
|
code = node[code_index].attr
|
||||||
|
|
||||||
assert iscode(code)
|
assert iscode(code)
|
||||||
code = Code(code, self.scanner, self.currentclass)
|
code = Code(code, self.scanner, self.currentclass)
|
||||||
|
Reference in New Issue
Block a user