You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Start Python3 class(superclass) handling
This commit is contained in:
BIN
test/bytecode_2.7/00_pass.pyc
Normal file
BIN
test/bytecode_2.7/00_pass.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
test/bytecode_3.4/00_import.pyc
Normal file
BIN
test/bytecode_3.4/00_import.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/00_pass.pyc
Normal file
BIN
test/bytecode_3.4/00_pass.pyc
Normal file
Binary file not shown.
Binary file not shown.
4
test/simple_source/simple_stmts/00_import.py
Normal file
4
test/simple_source/simple_stmts/00_import.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# Tests:
|
||||
|
||||
import sys
|
||||
from os import path
|
3
test/simple_source/simple_stmts/00_pass.py
Normal file
3
test/simple_source/simple_stmts/00_pass.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Tests:
|
||||
# assign ::= expr designator
|
||||
pass
|
@@ -370,9 +370,12 @@ class Python3Parser(PythonParser):
|
||||
|
||||
kwarg ::= LOAD_CONST expr
|
||||
|
||||
classdef ::= buildclass designator
|
||||
|
||||
# Python3 introduced LOAD_BUILD_CLASS
|
||||
classdef ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST
|
||||
CALL_FUNCTION_2 designator
|
||||
# FIXME: the below should be created by custom rules
|
||||
buildclass ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST LOAD_NAME CALL_FUNCTION_3
|
||||
buildclass ::= LOAD_BUILD_CLASS mkfunc LOAD_CONST CALL_FUNCTION_2
|
||||
|
||||
stmt ::= classdefdeco
|
||||
classdefdeco ::= classdefdeco1 designator
|
||||
|
@@ -1053,26 +1053,29 @@ class Walker(GenericASTTraversal, object):
|
||||
# class definition ('class X(A,B,C):')
|
||||
|
||||
cclass = self.currentclass
|
||||
|
||||
if self.version > 3.0:
|
||||
buildclass = node[1]
|
||||
self.currentclass = str(buildclass[1].pattr)
|
||||
build_list = node[0]
|
||||
subclass = build_list[1][0].attr
|
||||
else:
|
||||
buildclass = node[0]
|
||||
self.currentclass = str(buildclass[0].pattr)
|
||||
build_list = buildclass[1][0]
|
||||
subclass = buildclass[-3][0].attr
|
||||
|
||||
self.write('\n\n')
|
||||
self.currentclass = str(buildclass[0].pattr)
|
||||
self.write(self.indent, 'class ', self.currentclass)
|
||||
|
||||
self.print_super_classes(buildclass)
|
||||
if self.version > 3.0:
|
||||
self.print_super_classes3(build_list)
|
||||
else:
|
||||
self.print_super_classes(build_list)
|
||||
self.print_(':')
|
||||
|
||||
# class body
|
||||
self.indentMore()
|
||||
|
||||
if self.version > 3.0:
|
||||
self.build_class(buildclass[0].attr)
|
||||
else:
|
||||
self.build_class(buildclass[-3][0].attr)
|
||||
self.build_class(subclass)
|
||||
self.indentLess()
|
||||
|
||||
self.currentclass = cclass
|
||||
@@ -1086,7 +1089,6 @@ class Walker(GenericASTTraversal, object):
|
||||
n_classdefdeco2 = n_classdef
|
||||
|
||||
def print_super_classes(self, node):
|
||||
node = node[1][0]
|
||||
if not (node == 'build_list'):
|
||||
return
|
||||
|
||||
@@ -1100,6 +1102,29 @@ class Walker(GenericASTTraversal, object):
|
||||
|
||||
self.write(')')
|
||||
|
||||
def print_super_classes3(self, node):
|
||||
|
||||
# FIXME: put blow logic into grammar
|
||||
# as a custom rule
|
||||
i = 0
|
||||
for i, n in enumerate(node[:-1]):
|
||||
if n.type == 'LOAD_NAME':
|
||||
break
|
||||
pass
|
||||
|
||||
if i == 0:
|
||||
return
|
||||
self.write('(')
|
||||
line_separator = ', '
|
||||
sep = ''
|
||||
while i <= len(node) - 2:
|
||||
value = self.traverse(node[i])
|
||||
i += 1
|
||||
self.write(sep, value)
|
||||
sep = line_separator
|
||||
|
||||
self.write(')')
|
||||
|
||||
def n_mapexpr(self, node):
|
||||
"""
|
||||
prettyprint a mapexpr
|
||||
|
Reference in New Issue
Block a user