You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Correct 3.0 list comprehension parsing
This commit is contained in:
@@ -85,6 +85,11 @@ class Python30Parser(Python31Parser):
|
||||
LOAD_FAST FOR_ITER store comp_iter
|
||||
JUMP_BACK _come_froms POP_TOP JUMP_BACK
|
||||
|
||||
list_for ::= DUP_TOP STORE_FAST
|
||||
expr_or_arg
|
||||
FOR_ITER
|
||||
store list_iter jb_or_c
|
||||
|
||||
set_comp ::= set_comp_header
|
||||
LOAD_FAST FOR_ITER store comp_iter
|
||||
JUMP_BACK
|
||||
@@ -219,7 +224,7 @@ class Python30Parser(Python31Parser):
|
||||
# lc_body ::= LOAD_NAME expr LIST_APPEND
|
||||
# lc_body ::= expr LIST_APPEND
|
||||
# list_comp ::= BUILD_LIST_0 list_iter
|
||||
# list_for ::= expr FOR_ITER store list_iter jb_or_c
|
||||
list_for ::= expr FOR_ITER store list_iter jb_or_c
|
||||
# list_if ::= expr jmp_false list_iter
|
||||
# list_if ::= expr jmp_false_then list_iter
|
||||
# list_if_not ::= expr jmp_true list_iter
|
||||
|
@@ -384,7 +384,7 @@ class ComprehensionMixin:
|
||||
|
||||
while n in ("list_iter", "list_afor", "list_afor2", "comp_iter"):
|
||||
# iterate one nesting deeper
|
||||
if self.version == 3.0 and len(n) == 3:
|
||||
if self.version == (3, 0) and len(n) == 3:
|
||||
assert n[0] == "expr" and n[1] == "expr"
|
||||
n = n[1]
|
||||
elif n == "list_afor":
|
||||
@@ -397,11 +397,17 @@ class ComprehensionMixin:
|
||||
n = n[0]
|
||||
|
||||
if n in ("list_for", "comp_for"):
|
||||
if n[2] == "store" and not store:
|
||||
store = n[2]
|
||||
n_index = 3
|
||||
if ((n[2] == "store")
|
||||
or (self.version == (3, 0) and n[4] == "store") and not store):
|
||||
if self.version == (3, 0):
|
||||
store = n[4]
|
||||
n_index = 5
|
||||
else:
|
||||
store = n[2]
|
||||
if not comp_store:
|
||||
comp_store = store
|
||||
n = n[3]
|
||||
n = n[n_index]
|
||||
elif n in ("list_if", "list_if_not",
|
||||
"list_if37", "list_if37_not",
|
||||
"comp_if", "comp_if_not"):
|
||||
@@ -443,7 +449,11 @@ class ComprehensionMixin:
|
||||
self.write(": ")
|
||||
self.preorder(n[1])
|
||||
else:
|
||||
self.preorder(n[0])
|
||||
if self.version == (3, 0):
|
||||
body = n[1]
|
||||
else:
|
||||
body = n[0]
|
||||
self.preorder(body)
|
||||
|
||||
if node == "list_comp_async":
|
||||
self.write(" async")
|
||||
@@ -455,6 +465,7 @@ class ComprehensionMixin:
|
||||
|
||||
if comp_store:
|
||||
self.preorder(comp_store)
|
||||
comp_store = None
|
||||
else:
|
||||
self.preorder(store)
|
||||
|
||||
|
Reference in New Issue
Block a user