From ce66b121769bf7ec3b90bc313441203e010db008 Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Fri, 4 Nov 2022 23:42:28 -0400 Subject: [PATCH 1/4] Add missing ParserError2 in make_functions36 --- uncompyle6/semantics/make_function36.py | 1 + 1 file changed, 1 insertion(+) diff --git a/uncompyle6/semantics/make_function36.py b/uncompyle6/semantics/make_function36.py index 78bf9e26..4c29a936 100644 --- a/uncompyle6/semantics/make_function36.py +++ b/uncompyle6/semantics/make_function36.py @@ -25,6 +25,7 @@ from xdis import ( ) from uncompyle6.scanner import Code from uncompyle6.semantics.parser_error import ParserError +from uncompyle6.parser import ParserError as ParserError2 from uncompyle6.semantics.helper import ( find_all_globals, find_globals_and_nonlocals, From 98626ee16248d3461e198b69fa7025ed7baa7faf Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 5 Nov 2022 05:04:25 -0400 Subject: [PATCH 2/4] Misc linting --- uncompyle6/semantics/make_function36.py | 27 +++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/uncompyle6/semantics/make_function36.py b/uncompyle6/semantics/make_function36.py index 4c29a936..0546e756 100644 --- a/uncompyle6/semantics/make_function36.py +++ b/uncompyle6/semantics/make_function36.py @@ -39,11 +39,12 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): """Dump function definition, doc string, and function body in Python version 3.6 and above. """ + # MAKE_CLOSURE adds an additional closure slot # In Python 3.6 and above stack change again. I understand # 3.7 changes some of those changes, although I don't - # see it in this code yet. Yes, it is hard to follow + # see it in this code yet. Yes, it is hard to follow, # and I am sure I haven't been able to keep up. # Thank you, Python. @@ -85,16 +86,15 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): args_attr = args_node.attr if len(args_attr) == 3: - pos_args, kw_args, annotate_argc = args_attr + _, kw_args, annotate_argc = args_attr else: - pos_args, kw_args, annotate_argc, closure = args_attr + _, kw_args, annotate_argc, closure = args_attr if node[-2] != "docstring": i = -4 else: i = -5 - kw_pairs = 0 if annotate_argc: # Turn into subroutine and DRY with other use annotate_node = node[i] @@ -106,9 +106,9 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): ): types = [self.traverse(n, indent="") for n in annotate_node[:-2]] names = annotate_node[-2].attr - l = len(types) - assert l == len(names) - for i in range(l): + length = len(types) + assert length == len(names) + for i in range(length): annotate_dict[names[i]] = types[i] pass pass @@ -119,11 +119,6 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): # annotate = node[i] i -= 1 - if kw_args: - kw_node = node[pos_args] - if kw_node == "expr": - kw_node = kw_node[0] - defparams = [] # FIXME: DRY with code below default, kw_args, annotate_argc = args_node.attr[0:3] @@ -181,9 +176,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): if defparams: for i, defparam in enumerate(defparams): params.append( - build_param( - ast, paramnames[i], defparam, annotate_dict.get(paramnames[i]) - ) + build_param(paramnames[i], defparam, annotate_dict.get(paramnames[i])) ) for param in paramnames[i + 1 :]: @@ -236,7 +229,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): ends_in_comma = False if kwonlyargcount > 0: - if not (4 & code.co_flags): + if not 4 & code.co_flags: if argc > 0: self.write(", *, ") else: @@ -300,7 +293,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None): pass pass # handle others - other_kw = [c == None for c in kw_args] + other_kw = [c is None for c in kw_args] for i, flag in enumerate(other_kw): if flag: From 9d1cf50c5e4b613f2ae6ee3aeaa79e0ddcbc3c63 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 5 Nov 2022 10:15:45 -0400 Subject: [PATCH 3/4] Add generator expression Python 3.0 .. 3.2 --- uncompyle6/parsers/parse32.py | 6 ++++++ uncompyle6/parsers/parse37.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index be262985..29fbccf2 100644 --- a/uncompyle6/parsers/parse32.py +++ b/uncompyle6/parsers/parse32.py @@ -15,6 +15,12 @@ class Python32Parser(Python3Parser): store_locals ::= LOAD_FAST STORE_LOCALS """ + + def p_gen_comp(self, args): + """ + genexpr_func ::= LOAD_ARG FOR_ITER store comp_iter JUMP_BACK + """ + def p_32to35(self, args): """ if_exp ::= expr jmp_false expr jump_forward_else expr COME_FROM diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 80d9c6dd..e038f1d9 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -403,7 +403,7 @@ class Python37Parser(Python37BaseParser): list_if_not ::= expr jmp_true list_iter """ - def p_set_comp(self, args): + def p_gen_comp(self, args): """ comp_iter ::= comp_for comp_body ::= gen_comp_body From 8843686b495b8c3dd50fa9be570f01a24d6bfcf9 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 5 Nov 2022 10:31:00 -0400 Subject: [PATCH 4/4] Add generator expression Python 3.0 .. 3.2 --- uncompyle6/parsers/parse32.py | 2 +- uncompyle6/parsers/parse33.py | 3 ++- uncompyle6/parsers/parse37.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index 29fbccf2..c6de1637 100644 --- a/uncompyle6/parsers/parse32.py +++ b/uncompyle6/parsers/parse32.py @@ -16,7 +16,7 @@ class Python32Parser(Python3Parser): """ - def p_gen_comp(self, args): + def p_gen_comp32(self, args): """ genexpr_func ::= LOAD_ARG FOR_ITER store comp_iter JUMP_BACK """ diff --git a/uncompyle6/parsers/parse33.py b/uncompyle6/parsers/parse33.py index 8135db87..fc3ed940 100644 --- a/uncompyle6/parsers/parse33.py +++ b/uncompyle6/parsers/parse33.py @@ -19,8 +19,9 @@ class Python33Parser(Python32Parser): def customize_grammar_rules(self, tokens, customize): self.remove_rules(""" # 3.3+ adds POP_BLOCKS - whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP + genexpr_func ::= LOAD_ARG FOR_ITER store comp_iter JUMP_BACK whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP + whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP """) super(Python33Parser, self).customize_grammar_rules(tokens, customize) return diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index e038f1d9..4302e247 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -403,7 +403,7 @@ class Python37Parser(Python37BaseParser): list_if_not ::= expr jmp_true list_iter """ - def p_gen_comp(self, args): + def p_gen_comp37(self, args): """ comp_iter ::= comp_for comp_body ::= gen_comp_body