You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Expand annotate return to Python 3.4
This commit is contained in:
@@ -25,7 +25,7 @@ def test_grammar():
|
|||||||
unused_rhs = unused_rhs.union(set("""
|
unused_rhs = unused_rhs.union(set("""
|
||||||
except_pop_except genexpr classdefdeco2 listcomp
|
except_pop_except genexpr classdefdeco2 listcomp
|
||||||
""".split()))
|
""".split()))
|
||||||
if 3.1 <= PYTHON_VERSION <= 3.3:
|
if 3.1 <= PYTHON_VERSION <= 3.4:
|
||||||
unused_rhs.add("mkfunc_annotate")
|
unused_rhs.add("mkfunc_annotate")
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -47,5 +47,6 @@ def test_grammar():
|
|||||||
check_tokens(tokens, opcode_set)
|
check_tokens(tokens, opcode_set)
|
||||||
elif PYTHON_VERSION == 3.4:
|
elif PYTHON_VERSION == 3.4:
|
||||||
ignore_set.add('LOAD_CLASSNAME')
|
ignore_set.add('LOAD_CLASSNAME')
|
||||||
|
ignore_set.add('STORE_LOCALS')
|
||||||
opcode_set = set(s.opc.opname).union(ignore_set)
|
opcode_set = set(s.opc.opname).union(ignore_set)
|
||||||
check_tokens(tokens, opcode_set)
|
check_tokens(tokens, opcode_set)
|
||||||
|
@@ -246,6 +246,18 @@ class Python3Parser(PythonParser):
|
|||||||
c_stmts_opt34 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
c_stmts_opt34 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def p_def_annotations3(self, args):
|
||||||
|
"""
|
||||||
|
# Annotated functions
|
||||||
|
stmt ::= funcdef_annotate
|
||||||
|
funcdef_annotate ::= mkfunc_annotate designator
|
||||||
|
|
||||||
|
annotate_args ::= annotate_args annotate_arg
|
||||||
|
annotate_args ::= annotate_arg
|
||||||
|
annotate_arg ::= LOAD_CONST expr
|
||||||
|
"""
|
||||||
|
|
||||||
def p_come_from3(self, args):
|
def p_come_from3(self, args):
|
||||||
"""
|
"""
|
||||||
opt_come_from_except ::= COME_FROM_EXCEPT
|
opt_come_from_except ::= COME_FROM_EXCEPT
|
||||||
|
@@ -14,13 +14,6 @@ class Python32Parser(Python3Parser):
|
|||||||
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
|
binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR
|
||||||
stmt ::= store_locals
|
stmt ::= store_locals
|
||||||
store_locals ::= LOAD_FAST STORE_LOCALS
|
store_locals ::= LOAD_FAST STORE_LOCALS
|
||||||
|
|
||||||
stmt ::= funcdef_annotate
|
|
||||||
funcdef_annotate ::= mkfunc_annotate designator
|
|
||||||
|
|
||||||
annotate_args ::= annotate_args annotate_arg
|
|
||||||
annotate_args ::= annotate_arg
|
|
||||||
annotate_arg ::= LOAD_CONST expr
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -34,7 +27,6 @@ class Python32Parser(Python3Parser):
|
|||||||
rule = ('mkfunc_annotate ::= %s%sLOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
rule = ('mkfunc_annotate ::= %s%sLOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
||||||
(('pos_arg ' * (args_pos)),
|
(('pos_arg ' * (args_pos)),
|
||||||
('annotate_args ' * (annotate_args-1)), opname))
|
('annotate_args ' * (annotate_args-1)), opname))
|
||||||
print(rule)
|
|
||||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -9,9 +9,9 @@ from uncompyle6.parsers.parse32 import Python32Parser
|
|||||||
|
|
||||||
class Python33Parser(Python32Parser):
|
class Python33Parser(Python32Parser):
|
||||||
|
|
||||||
def p_33(self, args):
|
def p_33on(self, args):
|
||||||
"""
|
"""
|
||||||
# Python 3.3 adds yield from.
|
# Python 3.3+ adds yield from.
|
||||||
expr ::= yield_from
|
expr ::= yield_from
|
||||||
yield_from ::= expr expr YIELD_FROM
|
yield_from ::= expr expr YIELD_FROM
|
||||||
"""
|
"""
|
||||||
|
@@ -1,13 +1,13 @@
|
|||||||
# Copyright (c) 2016 Rocky Bernstein
|
# Copyright (c) 2016 Rocky Bernstein
|
||||||
"""
|
"""
|
||||||
spark grammar differences over Python 3.2 for Python 3.4
|
spark grammar differences over Python 3.3 for Python 3.4
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from uncompyle6.parser import PythonParserSingle
|
from uncompyle6.parser import PythonParserSingle
|
||||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||||
from uncompyle6.parsers.parse3 import Python3Parser
|
from uncompyle6.parsers.parse33 import Python33Parser
|
||||||
|
|
||||||
class Python34Parser(Python3Parser):
|
class Python34Parser(Python33Parser):
|
||||||
|
|
||||||
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
|
def __init__(self, debug_parser=PARSER_DEFAULT_DEBUG):
|
||||||
super(Python34Parser, self).__init__(debug_parser)
|
super(Python34Parser, self).__init__(debug_parser)
|
||||||
@@ -28,12 +28,6 @@ class Python34Parser(Python3Parser):
|
|||||||
iflaststmt ::= testexpr c_stmts_opt34
|
iflaststmt ::= testexpr c_stmts_opt34
|
||||||
c_stmts_opt34 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
c_stmts_opt34 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
||||||
|
|
||||||
# Python 3.3 added "yield from." Do it the same way as in
|
|
||||||
# 3.3
|
|
||||||
|
|
||||||
expr ::= yield_from
|
|
||||||
yield_from ::= expr expr YIELD_FROM
|
|
||||||
|
|
||||||
# Is this 3.4 only?
|
# Is this 3.4 only?
|
||||||
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
|
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
|
||||||
|
|
||||||
|
@@ -612,9 +612,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if version >= 3.0:
|
if version >= 3.0:
|
||||||
if 3.1 <= version <= 3.3:
|
if 3.1 <= version <= 3.4:
|
||||||
##########################
|
##########################
|
||||||
# Python 3.1 - 3.3
|
# Python 3.1 - 3.4
|
||||||
##########################
|
##########################
|
||||||
TABLE_DIRECT.update({
|
TABLE_DIRECT.update({
|
||||||
'funcdef_annotate': ( '\n\n%|def %c%c\n', -1, 0),
|
'funcdef_annotate': ( '\n\n%|def %c%c\n', -1, 0),
|
||||||
@@ -798,7 +798,7 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
self.n_mkfunc_annotate = n_mkfunc_annotate
|
self.n_mkfunc_annotate = n_mkfunc_annotate
|
||||||
|
|
||||||
|
|
||||||
elif version >= 3.4:
|
if version >= 3.4:
|
||||||
########################
|
########################
|
||||||
# Python 3.4+ Additions
|
# Python 3.4+ Additions
|
||||||
#######################
|
#######################
|
||||||
|
Reference in New Issue
Block a user