Fragment and other bugs

Part of the upgrade process
This commit is contained in:
rocky 2021-10-23 09:47:30 -04:00
parent 40a40b0bad
commit 71fe1e6c2c
2 changed files with 18 additions and 12 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
PYTHON_VERSION=3.7.7 PYTHON_VERSION=3.7.12
# FIXME put some of the below in a common routine # FIXME put some of the below in a common routine
function finish { function finish {

View File

@ -598,7 +598,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
def n_mkfunc(self, node): def n_mkfunc(self, node):
start = len(self.f.getvalue()) start = len(self.f.getvalue())
if self.version >= 3.3 or node[-2] == "kwargs": if self.version >= (3, 3) or node[-2] == "kwargs":
# LOAD_CONST code object .. # LOAD_CONST code object ..
# LOAD_CONST 'x0' if >= 3.3 # LOAD_CONST 'x0' if >= 3.3
# MAKE_FUNCTION .. # MAKE_FUNCTION ..
@ -657,9 +657,9 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.prec = 27 self.prec = 27
# FIXME: clean this up # FIXME: clean this up
if self.version > 3.0 and node == "dict_comp": if self.version >= (3, 1) and node == "dict_comp":
cn = node[1] cn = node[1]
elif self.version > 3.0 and node in ("generator_exp", "generator_exp_async"): elif self.version > (3, 1) and node in ("generator_exp", "generator_exp_async"):
if node[0] == "load_genexpr": if node[0] == "load_genexpr":
load_genexpr = node[0] load_genexpr = node[0]
elif node[1] == "load_genexpr": elif node[1] == "load_genexpr":
@ -927,7 +927,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
def n_generator_exp(self, node): def n_generator_exp(self, node):
start = len(self.f.getvalue()) start = len(self.f.getvalue())
self.write("(") self.write("(")
code_index = -6 if self.version > 3.2 else -5 code_index = -6 if self.version >= (3, 3) else -5
self.comprehension_walk(node, iter_index=4, code_index=code_index) self.comprehension_walk(node, iter_index=4, code_index=code_index)
self.write(")") self.write(")")
self.set_pos_info(node, start, len(self.f.getvalue())) self.set_pos_info(node, start, len(self.f.getvalue()))
@ -1063,7 +1063,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
# class definition ('class X(A,B,C):') # class definition ('class X(A,B,C):')
cclass = self.currentclass cclass = self.currentclass
if self.version > 3.0: if self.version >= (3, 1):
if node == "classdefdeco2": if node == "classdefdeco2":
currentclass = node[1][2].pattr currentclass = node[1][2].pattr
buildclass = node buildclass = node
@ -1127,7 +1127,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
start = len(self.f.getvalue()) start = len(self.f.getvalue())
self.write(self.indent, "class ", self.currentclass) self.write(self.indent, "class ", self.currentclass)
if self.version > 3.0: if self.version >= (3, 1):
self.print_super_classes3(subclass_info) self.print_super_classes3(subclass_info)
else: else:
self.print_super_classes(build_list) self.print_super_classes(build_list)
@ -1519,6 +1519,12 @@ class FragmentsWalker(pysource.SourceWalker, object):
sep = "" sep = ""
i += 1 i += 1
self.write("(") self.write("(")
if kwargs:
# Last arg is tuple of keyword values: omit
l = n - 1
else:
l = n
if kwargs: if kwargs:
# 3.6+ does this # 3.6+ does this
while j < i: while j < i:
@ -1545,7 +1551,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
pass pass
pass pass
else: else:
if self.version >= 3.6 and node[0] == "LOAD_CONST": if self.version >= (3, 6) and node[0] == "LOAD_CONST":
return return
value = self.traverse(node[0]) value = self.traverse(node[0])
self.write("(") self.write("(")
@ -1571,7 +1577,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.write("{") self.write("{")
self.set_pos_info(node[0], start, start + 1) self.set_pos_info(node[0], start, start + 1)
if self.version >= 3.0 and not self.is_pypy: if self.version >= (3, 0) and not self.is_pypy:
if node[0].kind.startswith("kvlist"): if node[0].kind.startswith("kvlist"):
# Python 3.5+ style key/value list in dict # Python 3.5+ style key/value list in dict
kv_node = node[0] kv_node = node[0]
@ -1643,14 +1649,14 @@ class FragmentsWalker(pysource.SourceWalker, object):
self.write(sep[1:]) self.write(sep[1:])
pass pass
elif node[0].kind.startswith("dict_entry"): elif node[0].kind.startswith("dict_entry"):
assert self.version >= 3.5 assert self.version >= (3, 5)
template = ("%C", (0, len(node[0]), ", **")) template = ("%C", (0, len(node[0]), ", **"))
self.template_engine(template, node[0]) self.template_engine(template, node[0])
sep = "" sep = ""
elif node[-1].kind.startswith("BUILD_MAP_UNPACK") or node[ elif node[-1].kind.startswith("BUILD_MAP_UNPACK") or node[
-1 -1
].kind.startswith("dict_entry"): ].kind.startswith("dict_entry"):
assert self.version >= 3.5 assert self.version >= (3, 5)
# FIXME: I think we can intermingle dict_comp's with other # FIXME: I think we can intermingle dict_comp's with other
# dictionary kinds of things. The most common though is # dictionary kinds of things. The most common though is
# a sequence of dict_comp's # a sequence of dict_comp's
@ -1674,7 +1680,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
else: else:
sep = "" sep = ""
opname = node[-1].kind opname = node[-1].kind
if self.is_pypy and self.version >= 3.5: if self.is_pypy and self.version >= (3, 5):
if opname.startswith("BUILD_CONST_KEY_MAP"): if opname.startswith("BUILD_CONST_KEY_MAP"):
keys = node[-2].attr keys = node[-2].attr
# FIXME: DRY this and the above # FIXME: DRY this and the above