From 50697bb79ecbc710663af2714cb13b13aaefd198 Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 16 Jan 2023 03:40:55 -0500 Subject: [PATCH] Improve set comprehension for Python 3.0 --- uncompyle6/parsers/parse30.py | 4 ++-- uncompyle6/semantics/gencomp.py | 2 +- uncompyle6/semantics/n_actions.py | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/uncompyle6/parsers/parse30.py b/uncompyle6/parsers/parse30.py index d4896259..9537d1ba 100644 --- a/uncompyle6/parsers/parse30.py +++ b/uncompyle6/parsers/parse30.py @@ -74,8 +74,8 @@ class Python30Parser(Python31Parser): # Need to keep LOAD_FAST as index 1 set_comp_header ::= BUILD_SET_0 DUP_TOP STORE_FAST set_comp_func ::= set_comp_header - LOAD_FAST FOR_ITER store comp_iter - JUMP_BACK POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST + LOAD_ARG FOR_ITER store comp_iter + JUMP_BACK COME_FROM POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST list_comp ::= list_comp_header diff --git a/uncompyle6/semantics/gencomp.py b/uncompyle6/semantics/gencomp.py index 1115d316..78d8677d 100644 --- a/uncompyle6/semantics/gencomp.py +++ b/uncompyle6/semantics/gencomp.py @@ -465,7 +465,7 @@ class ComprehensionMixin: self.write(": ") self.preorder(n[1]) else: - if self.version == (3, 0): + if self.version == (3, 0) and len(n) > 1: body = n[1] else: body = n[0] diff --git a/uncompyle6/semantics/n_actions.py b/uncompyle6/semantics/n_actions.py index aed3d366..fbbc326b 100644 --- a/uncompyle6/semantics/n_actions.py +++ b/uncompyle6/semantics/n_actions.py @@ -1093,7 +1093,12 @@ class NonterminalActions: self.write("{") if node[0] in ["LOAD_SETCOMP", "LOAD_DICTCOMP"]: if self.version == (3, 0): - iter_index = 6 + if len(node) >= 6: + iter_index = 6 + else: + assert node[1].kind.startswith("MAKE_FUNCTION") + iter_index = 2 + pass else: iter_index = 1 self.comprehension_walk_newer(node, iter_index=iter_index, code_index=0)