diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index 308cd71f..706ae64a 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -19,7 +19,7 @@ class Python27Parser(Python2Parser): lc_body ::= expr LIST_APPEND for_iter ::= GET_ITER COME_FROM FOR_ITER - stmt ::= set_comp + stmt ::= set_comp_func # Dictionary and set comprehensions were added in Python 2.7 @@ -30,8 +30,8 @@ class Python27Parser(Python2Parser): dict_comp_func ::= BUILD_MAP_0 LOAD_FAST FOR_ITER store comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST - set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter - JUMP_BACK RETURN_VALUE RETURN_LAST + set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter + JUMP_BACK RETURN_VALUE RETURN_LAST comp_body ::= dict_comp_body comp_body ::= set_comp_body diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index 23b9d431..923fe60f 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -61,13 +61,13 @@ class Python3Parser(PythonParser): jb_or_c ::= JUMP_BACK jb_or_c ::= CONTINUE - stmt ::= set_comp + stmt ::= set_comp_func - set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter - JUMP_BACK RETURN_VALUE RETURN_LAST + set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter + JUMP_BACK RETURN_VALUE RETURN_LAST - set_comp ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter - COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST + set_comp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER store comp_iter + COME_FROM JUMP_BACK RETURN_VALUE RETURN_LAST comp_body ::= dict_comp_body comp_body ::= set_comp_body diff --git a/uncompyle6/semantics/fragments.py b/uncompyle6/semantics/fragments.py index c7238fdf..24cb6108 100644 --- a/uncompyle6/semantics/fragments.py +++ b/uncompyle6/semantics/fragments.py @@ -676,7 +676,7 @@ class FragmentsWalker(pysource.SourceWalker, object): # skip over stmt return ret_expr ast = ast[0][0][0] store = None - if ast in ['set_comp', 'dictcomp_func']: + if ast in ['set_comp_func', 'dict_comp_func']: # Offset 0: BUILD_SET should have the span # of '{' self.gen_source(ast, code_name, {}) @@ -721,8 +721,8 @@ class FragmentsWalker(pysource.SourceWalker, object): pass # Python 2.7+ starts including set_comp_body - # Python 3.5+ starts including set_comp - assert n.kind in ('lc_body', 'comp_body', 'set_comp', 'set_comp_body'), ast + # Python 3.5+ starts including set_comp_func + assert n.kind in ('lc_body', 'comp_body', 'set_comp_func', 'set_comp_body'), ast assert store, "Couldn't find store in list/set comprehension" old_name = self.name @@ -849,7 +849,7 @@ class FragmentsWalker(pysource.SourceWalker, object): self.set_pos_info(node, start, len(self.f.getvalue())) self.prune() - def n_set_comp_expr(self, node): + def n_set_comp(self, node): start = len(self.f.getvalue()) self.write('{') if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: @@ -865,8 +865,8 @@ class FragmentsWalker(pysource.SourceWalker, object): self.prune() # FIXME: Not sure if below is general. Also, add dict_comp_func. - # 'set_comp': ("%|lambda %c: {%c for %c in %c%c}\n", 1, 3, 3, 1, 4) - def n_set_comp(self, node): + # 'set_comp_func': ("%|lambda %c: {%c for %c in %c%c}\n", 1, 3, 3, 1, 4) + def n_set_comp_func(self, node): setcomp_start = len(self.f.getvalue()) self.write(self.indent, "lambda ") param_node = node[1] diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index e1d051cd..f46176f7 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -1262,7 +1262,7 @@ class SourceWalker(GenericASTTraversal, object): self.write(')') self.prune() - def n_set_comp_expr(self, node): + def n_set_comp(self, node): self.write('{') if node[0] in ['LOAD_SETCOMP', 'LOAD_DICTCOMP']: self.comprehension_walk3(node, 1, 0) @@ -1272,7 +1272,7 @@ class SourceWalker(GenericASTTraversal, object): self.comprehension_walk(node, iter_index=4) self.write('}') self.prune() - n_dict_comp = n_set_comp_expr + n_dict_comp = n_set_comp def comprehension_walk3(self, node, iter_index, code_index=-5): """Non-closure-based comprehensions the way they are done in Python3. @@ -1297,7 +1297,7 @@ class SourceWalker(GenericASTTraversal, object): ast = ast[0] store = None - if ast in ['set_comp', 'dict_comp_func']: + if ast in ['set_comp_func', 'dict_comp_func']: for k in ast: if k == 'comp_iter': n = k @@ -1338,8 +1338,8 @@ class SourceWalker(GenericASTTraversal, object): pass # Python 2.7+ starts including set_comp_body - # Python 3.5+ starts including set_comp - assert n.kind in ('lc_body', 'comp_body', 'set_comp', 'set_comp_body'), ast + # Python 3.5+ starts including set_comp_func + assert n.kind in ('lc_body', 'comp_body', 'set_comp_func', 'set_comp_body'), ast assert store, "Couldn't find store in list/set comprehension" # A problem created with later Python code generation is that there