Skip to content

Commit 50697bb

Browse files
committed
Improve set comprehension for Python 3.0
1 parent 137dd64 commit 50697bb

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

uncompyle6/parsers/parse30.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def p_30(self, args):
7474
# Need to keep LOAD_FAST as index 1
7575
set_comp_header ::= BUILD_SET_0 DUP_TOP STORE_FAST
7676
set_comp_func ::= set_comp_header
77-
LOAD_FAST FOR_ITER store comp_iter
78-
JUMP_BACK POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST
77+
LOAD_ARG FOR_ITER store comp_iter
78+
JUMP_BACK COME_FROM POP_TOP JUMP_BACK RETURN_VALUE RETURN_LAST
7979
8080
list_comp_header ::= BUILD_LIST_0 DUP_TOP STORE_FAST
8181
list_comp ::= list_comp_header

uncompyle6/semantics/gencomp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def comprehension_walk_newer(
465465
self.write(": ")
466466
self.preorder(n[1])
467467
else:
468-
if self.version == (3, 0):
468+
if self.version == (3, 0) and len(n) > 1:
469469
body = n[1]
470470
else:
471471
body = n[0]

uncompyle6/semantics/n_actions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,12 @@ def n_set_comp(self, node):
10931093
self.write("{")
10941094
if node[0] in ["LOAD_SETCOMP", "LOAD_DICTCOMP"]:
10951095
if self.version == (3, 0):
1096-
iter_index = 6
1096+
if len(node) >= 6:
1097+
iter_index = 6
1098+
else:
1099+
assert node[1].kind.startswith("MAKE_FUNCTION")
1100+
iter_index = 2
1101+
pass
10971102
else:
10981103
iter_index = 1
10991104
self.comprehension_walk_newer(node, iter_index=iter_index, code_index=0)

0 commit comments

Comments
 (0)