diff --git a/pytest/test_grammar.py b/pytest/test_grammar.py index 547b7f1e..604298dc 100644 --- a/pytest/test_grammar.py +++ b/pytest/test_grammar.py @@ -25,7 +25,7 @@ def test_grammar(): unused_rhs = unused_rhs.union(set(""" except_pop_except genexpr classdefdeco2 listcomp """.split())) - if 3.1 <= PYTHON_VERSION <= 3.3: + if 3.1 <= PYTHON_VERSION <= 3.4: unused_rhs.add("mkfunc_annotate") pass else: @@ -47,5 +47,6 @@ def test_grammar(): check_tokens(tokens, opcode_set) elif PYTHON_VERSION == 3.4: ignore_set.add('LOAD_CLASSNAME') + ignore_set.add('STORE_LOCALS') opcode_set = set(s.opc.opname).union(ignore_set) check_tokens(tokens, opcode_set) diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 12e4beb7..8eb0e04d 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -246,6 +246,18 @@ class Python3Parser(PythonParser): 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): """ opt_come_from_except ::= COME_FROM_EXCEPT diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index 5a94dad9..b6d5a3c6 100644 --- a/uncompyle6/parsers/parse32.py +++ b/uncompyle6/parsers/parse32.py @@ -14,13 +14,6 @@ class Python32Parser(Python3Parser): binary_subscr2 ::= expr expr DUP_TOP_TWO BINARY_SUBSCR stmt ::= 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 @@ -34,7 +27,6 @@ class Python32Parser(Python3Parser): rule = ('mkfunc_annotate ::= %s%sLOAD_CONST LOAD_CONST EXTENDED_ARG %s' % (('pos_arg ' * (args_pos)), ('annotate_args ' * (annotate_args-1)), opname)) - print(rule) self.add_unique_rule(rule, opname, token.attr, customize) diff --git a/uncompyle6/parsers/parse33.py b/uncompyle6/parsers/parse33.py index 38037613..dd43c12e 100644 --- a/uncompyle6/parsers/parse33.py +++ b/uncompyle6/parsers/parse33.py @@ -9,9 +9,9 @@ from uncompyle6.parsers.parse32 import 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 yield_from ::= expr expr YIELD_FROM """ diff --git a/uncompyle6/parsers/parse34.py b/uncompyle6/parsers/parse34.py index cf094af6..bce24488 100644 --- a/uncompyle6/parsers/parse34.py +++ b/uncompyle6/parsers/parse34.py @@ -1,13 +1,13 @@ # 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 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): super(Python34Parser, self).__init__(debug_parser) @@ -28,12 +28,6 @@ class Python34Parser(Python3Parser): iflaststmt ::= testexpr c_stmts_opt34 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? yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 0079edec..71d57f29 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -612,9 +612,9 @@ class SourceWalker(GenericASTTraversal, object): }) 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({ '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 - elif version >= 3.4: + if version >= 3.4: ######################## # Python 3.4+ Additions #######################