You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Python 3.0..3.2 bug in LOAD_FAST/STORE_LOCAL
LOAD_FAST '__locals__' STORE_LOCALS '' Also have to adjust doc constants for this crap astnode.py: minor format change
This commit is contained in:
BIN
test/bytecode_3.2/06_classbug.pyc
Normal file
BIN
test/bytecode_3.2/06_classbug.pyc
Normal file
Binary file not shown.
@@ -28,7 +28,8 @@ class AST(UserList):
|
|||||||
else:
|
else:
|
||||||
return self.type == o
|
return self.type == o
|
||||||
|
|
||||||
def __hash__(self): return hash(self.type)
|
def __hash__(self):
|
||||||
|
return hash(self.type)
|
||||||
|
|
||||||
def __repr__(self, indent=''):
|
def __repr__(self, indent=''):
|
||||||
rv = str(self.type)
|
rv = str(self.type)
|
||||||
|
@@ -19,7 +19,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
from uncompyle6.parser import PythonParser, nop_func
|
from uncompyle6.parser import PythonParser, nop_func
|
||||||
from uncompyle6.parsers.astnode import AST
|
from uncompyle6.parsers.astnode import AST
|
||||||
from spark_parser import GenericASTBuilder, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
from uncompyle6 import PYTHON3
|
from uncompyle6 import PYTHON3
|
||||||
|
|
||||||
class Python3Parser(PythonParser):
|
class Python3Parser(PythonParser):
|
||||||
@@ -154,6 +154,9 @@ class Python3Parser(PythonParser):
|
|||||||
designList ::= designator designator
|
designList ::= designator designator
|
||||||
designList ::= designator DUP_TOP designList
|
designList ::= designator DUP_TOP designList
|
||||||
|
|
||||||
|
# FIXME: Store local is only used in Python 3.2
|
||||||
|
designator ::= STORE_LOCALS
|
||||||
|
|
||||||
designator ::= STORE_FAST
|
designator ::= STORE_FAST
|
||||||
designator ::= STORE_NAME
|
designator ::= STORE_NAME
|
||||||
designator ::= STORE_GLOBAL
|
designator ::= STORE_GLOBAL
|
||||||
|
@@ -93,7 +93,6 @@ RETURN_LOCALS = AST('return_stmt',
|
|||||||
[ AST('ret_expr', [AST('expr', [ Token('LOAD_LOCALS') ])]),
|
[ AST('ret_expr', [AST('expr', [ Token('LOAD_LOCALS') ])]),
|
||||||
Token('RETURN_VALUE')])
|
Token('RETURN_VALUE')])
|
||||||
|
|
||||||
|
|
||||||
NONE = AST('expr', [ NoneToken ] )
|
NONE = AST('expr', [ NoneToken ] )
|
||||||
|
|
||||||
RETURN_NONE = AST('stmt',
|
RETURN_NONE = AST('stmt',
|
||||||
@@ -1224,6 +1223,14 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
n_unpack_w_parens = n_unpack
|
n_unpack_w_parens = n_unpack
|
||||||
|
|
||||||
|
def n_assign(self, node):
|
||||||
|
# A horrible hack for Python 3.0 .. 3.2
|
||||||
|
if 3.0 <= self.version <= 3.2 and len(node) == 2:
|
||||||
|
if (node[0][0] == 'LOAD_FAST' and node[0][0].pattr == '__locals__' and
|
||||||
|
node[1][0].type == 'STORE_LOCALS'):
|
||||||
|
self.prune()
|
||||||
|
self.default(node)
|
||||||
|
|
||||||
def n_assign2(self, node):
|
def n_assign2(self, node):
|
||||||
for n in node[-2:]:
|
for n in node[-2:]:
|
||||||
if n[0] == 'unpack':
|
if n[0] == 'unpack':
|
||||||
@@ -1538,12 +1545,20 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# if docstring exists, dump it
|
# if docstring exists, dump it
|
||||||
if (code.co_consts and code.co_consts[0] is not None
|
if (code.co_consts and code.co_consts[0] is not None and len(ast) > 0):
|
||||||
and len(ast) > 0 and ast[0][0] == ASSIGN_DOC_STRING(code.co_consts[0])):
|
do_doc = False
|
||||||
if self.hide_internal:
|
if (ast[0][0] == ASSIGN_DOC_STRING(code.co_consts[0])):
|
||||||
|
i = 0
|
||||||
|
do_doc = True
|
||||||
|
elif (len(ast) > 2 and 3.0 <= self.version <= 3.2 and
|
||||||
|
ast[2][0] == ASSIGN_DOC_STRING(code.co_consts[0])):
|
||||||
|
i = 2
|
||||||
|
do_doc = True
|
||||||
|
if do_doc and self.hide_internal:
|
||||||
self.print_docstring(indent, code.co_consts[0])
|
self.print_docstring(indent, code.co_consts[0])
|
||||||
self.print_()
|
self.print_()
|
||||||
del ast[0]
|
del ast[i]
|
||||||
|
|
||||||
|
|
||||||
# the function defining a class normally returns locals(); we
|
# the function defining a class normally returns locals(); we
|
||||||
# don't want this to show up in the source, thus remove the node
|
# don't want this to show up in the source, thus remove the node
|
||||||
|
Reference in New Issue
Block a user