diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 7bdf17ff..95465962 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -775,7 +775,7 @@ class Python3Parser(PythonParser): # FIXME: Use the attr # so this doesn't run into exponential parsing time. if opname.startswith("BUILD_MAP_UNPACK"): - # FIXME: start here. The LHS should be dict_unmap, not dict. + # FIXME: start here. The LHS should be dict_unpack, not dict. # FIXME: really we need a combination of dict_entry-like things. # It just so happens the most common case is not to mix # dictionary comphensions with dictionary, elements @@ -786,8 +786,8 @@ class Python3Parser(PythonParser): ) self.addRule(rule, nop_func) rule = """ - expr ::= dict_unmap - dict_unmap ::= %s%s + expr ::= dict_unpack + dict_unpack ::= %s%s """ % ( "expr " * token.attr, opname, diff --git a/uncompyle6/parsers/parse35.py b/uncompyle6/parsers/parse35.py index edfc4f92..855af766 100644 --- a/uncompyle6/parsers/parse35.py +++ b/uncompyle6/parsers/parse35.py @@ -201,8 +201,8 @@ class Python35Parser(Python34Parser): self.addRule(rules_str, nop_func) elif opname == 'BUILD_MAP_UNPACK': self.addRule(""" - expr ::= dict_unmap - dict_unmap ::= dict_comp BUILD_MAP_UNPACK + expr ::= dict_unpack + dict_unpack ::= dict_comp BUILD_MAP_UNPACK """, nop_func) elif opname == 'SETUP_WITH': diff --git a/uncompyle6/parsers/parse37base.py b/uncompyle6/parsers/parse37base.py index bb062689..50496c9c 100644 --- a/uncompyle6/parsers/parse37base.py +++ b/uncompyle6/parsers/parse37base.py @@ -336,8 +336,8 @@ class Python37BaseParser(PythonParser): if opname == "BUILD_MAP_UNPACK": self.addRule( """ - expr ::= dict_unmap - dict_unmap ::= dict_comp BUILD_MAP_UNPACK + expr ::= dict_unpack + dict_unpack ::= dict_comp BUILD_MAP_UNPACK """, nop_func, ) @@ -367,7 +367,7 @@ class Python37BaseParser(PythonParser): # FIXME: Use the attr # so this doesn't run into exponential parsing time. if opname.startswith("BUILD_MAP_UNPACK"): - # FIXME: start here. The LHS should be dict_unmap, not dict. + # FIXME: start here. The LHS should be dict_unpack, not dict. # FIXME: really we need a combination of dict_entry-like things. # It just so happens the most common case is not to mix # dictionary comphensions with dictionary, elements @@ -375,8 +375,8 @@ class Python37BaseParser(PythonParser): rule = "dict ::= %s%s" % ("dict_comp " * token.attr, opname) self.addRule(rule, nop_func) rule = """ - expr ::= dict_unmap - dict_unmap ::= %s%s + expr ::= dict_unpack + dict_unpack ::= %s%s """ % ( "expr " * token.attr, opname, diff --git a/uncompyle6/semantics/customize35.py b/uncompyle6/semantics/customize35.py index 02709b8e..f95f3822 100644 --- a/uncompyle6/semantics/customize35.py +++ b/uncompyle6/semantics/customize35.py @@ -51,7 +51,7 @@ def customize_for_version35(self, version): (2, "store"), 3, ), - "dict_unmap": ("{**%C}", (0, -1, ", **")), + "dict_unpack": ("{**%C}", (0, -1, ", **")), # "unmapexpr": ( "{**%c}", 0), # done by n_unmapexpr } ) diff --git a/uncompyle6/semantics/customize36.py b/uncompyle6/semantics/customize36.py index 7c60f1d0..1074fca8 100644 --- a/uncompyle6/semantics/customize36.py +++ b/uncompyle6/semantics/customize36.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019-2020 by Rocky Bernstein +# Copyright (c) 2019-2021 by Rocky Bernstein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -37,14 +37,16 @@ def escape_format(s): def customize_for_version36(self, version): - PRECEDENCE["call_kw"] = 0 - PRECEDENCE["call_kw36"] = 1 - PRECEDENCE["call_ex"] = 1 - PRECEDENCE["call_ex_kw"] = 1 - PRECEDENCE["call_ex_kw2"] = 1 - PRECEDENCE["call_ex_kw3"] = 1 - PRECEDENCE["call_ex_kw4"] = 1 - PRECEDENCE["dict_unmap"] = 0 # **{ ... } + + # fmt: off + PRECEDENCE["call_kw"] = 0 + PRECEDENCE["call_kw36"] = 1 + PRECEDENCE["call_ex"] = 1 + PRECEDENCE["call_ex_kw"] = 1 + PRECEDENCE["call_ex_kw2"] = 1 + PRECEDENCE["call_ex_kw3"] = 1 + PRECEDENCE["call_ex_kw4"] = 1 + PRECEDENCE["dict_pack"] = 0 # **{ ... } PRECEDENCE["formatted_value1"] = 100 TABLE_DIRECT.update( @@ -52,7 +54,7 @@ def customize_for_version36(self, version): "ann_assign_init_value": ( "%|%c = %p\n", (-1, "store_annotation"), - (0, "expr", 200), + (0, "expr", 200), ), "ann_assign_no_init": ("%|%c\n", (0, "store_annotation")), "async_for_stmt36": ( @@ -61,28 +63,32 @@ def customize_for_version36(self, version): (1, "expr"), (18, "for_block"), ), - "call_ex": ("%c(%p)", (0, "expr"), (1, 100)), - "except_return": ("%|except:\n%+%c%-", 3), - "func_args36": ("%c(**", 0), + "call_ex": ("%c(%p)", (0, "expr"), (1, 100)), + "except_return": ("%|except:\n%+%c%-", 3), + "func_args36": ("%c(**", 0), + # This comes from 3.7. Eventually we will rebase from 3.7 # and then this can go away - "if_exp37": ("%p if %c else %c", (1, "expr", 27), 0, 3), - "ifstmtl": ("%|if %c:\n%+%c%-", (0, "testexpr"), (1, "_ifstmts_jumpl")), - "try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2), - "tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3), + "if_exp37": ("%p if %c else %c", (1, "expr", 27), 0, 3), + + "ifstmtl": ("%|if %c:\n%+%c%-", + (0, "testexpr"), (1, "_ifstmts_jumpl")), + "try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2), + "tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3), "tryfinally_return_stmt": ("%|try:\n%+%c%-%|finally:\n%+%|return%-\n\n", 1), - "unpack_list": ("*%c", (0, "list")), - "store_annotation": ("%[1]{pattr}: %c", 0), + "unpack_list": ("*%c", (0, "list")), + "store_annotation": ("%[1]{pattr}: %c", 0), } ) TABLE_R.update( { - "CALL_FUNCTION_EX": ("%c(*%P)", 0, (1, 2, ", ", 100)), + "CALL_FUNCTION_EX": ("%c(*%P)", 0, (1, 2, ", ", 100)), # Not quite right "CALL_FUNCTION_EX_KW": ("%c(**%C)", 0, (2, 3, ",")), } ) + # fmt: on def build_unpack_tuple_with_call(node): n = node[0] diff --git a/uncompyle6/semantics/customize37.py b/uncompyle6/semantics/customize37.py index 27fa41b1..6f1d9ef3 100644 --- a/uncompyle6/semantics/customize37.py +++ b/uncompyle6/semantics/customize37.py @@ -22,22 +22,24 @@ from uncompyle6.semantics.consts import ( maxint, ) + def customize_for_version37(self, version): ######################## # Python 3.7+ changes ####################### - PRECEDENCE["attribute37"] = 2 - PRECEDENCE["call_ex"] = 1 - PRECEDENCE["call_ex_kw"] = 1 - PRECEDENCE["call_ex_kw2"] = 1 - PRECEDENCE["call_ex_kw3"] = 1 - PRECEDENCE["call_ex_kw4"] = 1 - PRECEDENCE["call_kw"] = 0 - PRECEDENCE["call_kw36"] = 1 + # fmt: off + PRECEDENCE["attribute37"] = 2 + PRECEDENCE["call_ex"] = 1 + PRECEDENCE["call_ex_kw"] = 1 + PRECEDENCE["call_ex_kw2"] = 1 + PRECEDENCE["call_ex_kw3"] = 1 + PRECEDENCE["call_ex_kw4"] = 1 + PRECEDENCE["call_kw"] = 0 + PRECEDENCE["call_kw36"] = 1 PRECEDENCE["formatted_value1"] = 100 - PRECEDENCE["if_exp_37a"] = 28 - PRECEDENCE["if_exp_37b"] = 28 + PRECEDENCE["if_exp_37a"] = 28 + PRECEDENCE["if_exp_37b"] = 28 TABLE_DIRECT.update( { @@ -160,11 +162,12 @@ def customize_for_version37(self, version): "testfalsel": ("not %c", (0, "expr")), "try_except36": ("%|try:\n%+%c%-%c\n\n", 1, -2), "tryfinally36": ("%|try:\n%+%c%-%|finally:\n%+%c%-\n\n", (1, "returns"), 3), - "dict_unmap": ("{**%C}", (0, -1, ", **")), + "dict_unpack": ("{**%C}", (0, -1, ", **")), "unpack_list": ("*%c", (0, "list")), "yield_from": ("yield from %c", (0, "expr")), } ) + # fmt: on def gen_function_parens_adjust(mapping_key, node): """If we can avoid the outer parenthesis @@ -279,11 +282,8 @@ def customize_for_version37(self, version): else: template = "%c(%p)" self.template_engine( - (template, - (0, "expr"), - (1, PRECEDENCE["yield"]-1)), - node - ) + (template, (0, "expr"), (1, PRECEDENCE["yield"] - 1)), node + ) self.prec = p self.prune() else: @@ -299,6 +299,7 @@ def customize_for_version37(self, version): self.default(node[0]) else: self.default(node) + self.n_compare_chained = n_compare_chained def n_importlist37(node): @@ -309,7 +310,7 @@ def customize_for_version37(self, version): for i in range(n, -1, -1): if node[i] != "ROT_TWO": break - self.template_engine(("%C", (0, i + 1, ', ')), node) + self.template_engine(("%C", (0, i + 1, ", ")), node) self.prune() return @@ -323,4 +324,5 @@ def customize_for_version37(self, version): self.comprehension_walk_newer(node, iter_index=3, code_index=0) self.write("]") self.prune() + self.n_list_comp_async = n_list_comp_async