diff --git a/uncompyle6/parsers/parse32.py b/uncompyle6/parsers/parse32.py index be262985..c6de1637 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_comp32(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/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 80d9c6dd..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_set_comp(self, args): + def p_gen_comp37(self, args): """ comp_iter ::= comp_for comp_body ::= gen_comp_body diff --git a/uncompyle6/semantics/make_function36.py b/uncompyle6/semantics/make_function36.py index 78bf9e26..0546e756 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, @@ -38,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. @@ -84,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] @@ -105,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 @@ -118,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] @@ -180,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 :]: @@ -235,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: @@ -299,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: