Merge branch 'master' into python-3.3-to-3.5

This commit is contained in:
rocky
2022-11-04 02:06:00 -04:00
3 changed files with 25 additions and 4 deletions

View File

@@ -102,6 +102,11 @@ class Python30Parser(Python31Parser):
LOAD_FAST FOR_ITER store dict_comp_iter
JUMP_BACK _come_froms POP_TOP JUMP_BACK
dict_comp_func ::= BUILD_MAP_0
DUP_TOP STORE_FAST
LOAD_ARG FOR_ITER store
dict_comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
stmt ::= try_except30
try_except30 ::= SETUP_EXCEPT suite_stmts_opt
_come_froms pt_bp

View File

@@ -267,6 +267,7 @@ class ComprehensionMixin:
is_30_dict_comp = False
store = None
if node == "list_comp_async":
# We have two different kinds of grammar rules:
# list_comp_async ::= LOAD_LISTCOMP LOAD_STR MAKE_FUNCTION_0 expr ...
@@ -593,7 +594,7 @@ class ComprehensionMixin:
collections = [node[-3]]
list_ifs = []
if self.version[:2] == (3, 0) and n != "list_iter":
if self.version[:2] == (3, 0) and n.kind != "list_iter":
# FIXME 3.0 is a snowflake here. We need
# special code for this. Not sure if this is totally
# correct.
@@ -636,7 +637,12 @@ class ComprehensionMixin:
# FIXME: adjust for set comprehension
if n == "list_for":
stores.append(n[2])
n = n[3]
if self.version[:2] == (3, 0):
body_index = 5
else:
body_index = 3
n = n[body_index]
if n[0] == "list_for":
# Dog-paddle down largely singleton reductions
# to find the collection (expr)
@@ -668,7 +674,11 @@ class ComprehensionMixin:
assert n == "lc_body", tree
self.preorder(n[0])
if self.version[:2] == (3, 0):
body_index = 1
else:
body_index = 0
self.preorder(n[body_index])
# FIXME: add indentation around "for"'s and "in"'s
n_colls = len(collections)
@@ -682,6 +692,8 @@ class ComprehensionMixin:
self.write(" async")
pass
self.write(" for ")
if self.version[:2] == (3, 0):
store = token
self.preorder(store)
self.write(" in ")
self.preorder(collections[i])

View File

@@ -1085,7 +1085,11 @@ class NonterminalActions:
def n_set_comp(self, node):
self.write("{")
if node[0] in ["LOAD_SETCOMP", "LOAD_DICTCOMP"]:
self.comprehension_walk_newer(node, 1, 0)
if self.version == (3, 0):
iter_index = 6
else:
iter_index = 1
self.comprehension_walk_newer(node, iter_index=iter_index, code_index=0)
elif node[0].kind == "load_closure" and self.version >= (3, 0):
self.closure_walk(node, collection_index=4)
else: