Merge branch 'python-3.0-to-3.2' into python-2.4-to-2.7

This commit is contained in:
rocky
2024-02-24 18:22:34 -05:00
15 changed files with 67 additions and 36 deletions

View File

@@ -1,6 +1,13 @@
SKIP_TESTS=( SKIP_TESTS=(
[test_descr.py]=1 # FIXME: Works on c90ff51? [test_descr.py]=1 # FIXME: Works on c90ff51?
[test_cmath.py]=1 # FIXME
# AssertionError: rect1000: rect(complex(0.0, 0.0))
# Expected: complex(0.0, 0.0)
# Received: complex(0.0, -1.0)
# Received value insufficiently close to expected value.
[test_cmd_line.py]=1 [test_cmd_line.py]=1
[test_collections.py]=1 [test_collections.py]=1
[test_concurrent_futures.py]=1 # too long to run over 46 seconds by itself [test_concurrent_futures.py]=1 # too long to run over 46 seconds by itself

View File

@@ -11,7 +11,7 @@ SKIP_TESTS=(
[test_itertools.py]=1 [test_itertools.py]=1
[test_buffer.py]=1 # FIXME: Works on c90ff51 [test_buffer.py]=1 # FIXME: Works on c90ff51
[test_cmath.py]=1 # FIXME: Works on c90ff51 [test_cmath.py]=pytest
[test_atexit.py]=1 # The atexit test starting at 3.3 looks for specific comments in error lines [test_atexit.py]=1 # The atexit test starting at 3.3 looks for specific comments in error lines

View File

@@ -1,6 +1,6 @@
SKIP_TESTS=( SKIP_TESTS=(
[test_ast.py]=1 # FIXME: Works on c90ff51 [test_ast.py]=1 # FIXME: Works on c90ff51
[test_cmath.py]=1 # FIXME: Works on c90ff51 [test_cmath.py]=1 # fails on its own
[test_format.py]=1 # FIXME: Works on c90ff51 [test_format.py]=1 # FIXME: Works on c90ff51
[test_ftplib.py]=1 # FIXME: Works on c90ff51 [test_ftplib.py]=1 # FIXME: Works on c90ff51
[test_slice.py]=1 # FIXME: Works on c90ff51 [test_slice.py]=1 # FIXME: Works on c90ff51

View File

@@ -36,7 +36,7 @@ SKIP_TESTS=(
[test_bdb.py]=1 # [test_bdb.py]=1 #
[test_buffer.py]=1 # parse error [test_buffer.py]=1 # parse error
[test_clinic.py]=1 # it fails on its own [test_clinic.py]=1 # it fails on its own
[test_cmath.py]=1 # test assertion failure [test_cmath.py]=pytest
[test_cmd_line.py]=1 # Interactive? [test_cmd_line.py]=1 # Interactive?
[test_cmd_line_script.py]=1 [test_cmd_line_script.py]=1
[test_compileall.py]=1 # fails on its own [test_compileall.py]=1 # fails on its own

View File

@@ -69,7 +69,7 @@ SKIP_TESTS=(
[test_cgi.py]=1 # parse error [test_cgi.py]=1 # parse error
[test_cgitb.py]=1 # parse error [test_cgitb.py]=1 # parse error
[test_clinic.py]=1 # it fails on its own [test_clinic.py]=1 # it fails on its own
[test_cmath.py]=1 # test assertion failure [test_cmath.py]=pytest
[test_cmd.py]=1 # parse error [test_cmd.py]=1 # parse error
[test_cmd_line.py]=1 # Interactive? [test_cmd_line.py]=1 # Interactive?
[test_cmd_line_script.py]=1 [test_cmd_line_script.py]=1

View File

@@ -193,7 +193,7 @@ if [[ -n $1 ]] ; then
if (( ${#files_ary[@]} == 1 || DONT_SKIP_TESTS == 1 )) ; then if (( ${#files_ary[@]} == 1 || DONT_SKIP_TESTS == 1 )) ; then
for file in $files; do for file in $files; do
if (( SKIP_TESTS[$file] != "pytest" )); then if (( SKIP_TESTS[$file] != "pytest" )); then
SKIP_TESTS[$file] = 1; SKIP_TESTS[$file]=1;
fi fi
done done
fi fi

View File

@@ -253,6 +253,7 @@ class Scanner3(Scanner):
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
opc=self.opc, opc=self.opc,
optype=None,
) )
) )
for j in range(collection_start, i): for j in range(collection_start, i):
@@ -266,6 +267,7 @@ class Scanner3(Scanner):
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
opc=self.opc, opc=self.opc,
optype=insts[j].optype,
) )
) )
new_tokens.append( new_tokens.append(
@@ -278,6 +280,7 @@ class Scanner3(Scanner):
has_arg=t.has_arg, has_arg=t.has_arg,
has_extended_arg=False, has_extended_arg=False,
opc=t.opc, opc=t.opc,
optype=None,
) )
) )
return new_tokens return new_tokens
@@ -324,6 +327,7 @@ class Scanner3(Scanner):
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
opc=self.opc, opc=self.opc,
optype=None,
) )
) )
for j in range(collection_start, i, 2): for j in range(collection_start, i, 2):
@@ -349,6 +353,7 @@ class Scanner3(Scanner):
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
opc=self.opc, opc=self.opc,
optype=insts[j + 1].optype,
) )
) )
new_tokens.append( new_tokens.append(
@@ -361,6 +366,7 @@ class Scanner3(Scanner):
has_arg=t.has_arg, has_arg=t.has_arg,
has_extended_arg=False, has_extended_arg=False,
opc=t.opc, opc=t.opc,
optype=t.optype,
) )
) )
return new_tokens return new_tokens

View File

@@ -89,6 +89,7 @@ class Scanner37(Scanner37Base):
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
opc=self.opc, opc=self.opc,
optype=None,
) )
) )
for j in range(collection_start, i): for j in range(collection_start, i):
@@ -102,6 +103,7 @@ class Scanner37(Scanner37Base):
has_arg=True, has_arg=True,
has_extended_arg=False, has_extended_arg=False,
opc=self.opc, opc=self.opc,
optype=tokens[j].optype,
) )
) )
new_tokens.append( new_tokens.append(

View File

@@ -352,6 +352,7 @@ class Scanner37Base(Scanner):
has_arg=True, has_arg=True,
opc=self.opc, opc=self.opc,
has_extended_arg=False, has_extended_arg=False,
optype=inst.optype,
), ),
) )
jump_idx += 1 jump_idx += 1
@@ -423,6 +424,7 @@ class Scanner37Base(Scanner):
has_arg=inst.has_arg, has_arg=inst.has_arg,
opc=self.opc, opc=self.opc,
has_extended_arg=inst.has_extended_arg, has_extended_arg=inst.has_extended_arg,
optype=inst.optype,
), ),
) )
continue continue
@@ -524,6 +526,7 @@ class Scanner37Base(Scanner):
has_arg=inst.has_arg, has_arg=inst.has_arg,
opc=self.opc, opc=self.opc,
has_extended_arg=inst.has_extended_arg, has_extended_arg=inst.has_extended_arg,
optype=inst.optype,
), ),
) )
pass pass

View File

@@ -68,11 +68,13 @@ class Token: # Python 2.4 can't have empty ()
has_arg=None, has_arg=None,
opc=None, opc=None,
has_extended_arg=False, has_extended_arg=False,
optype=None,
): ):
self.kind = intern(opname) self.kind = intern(opname)
self.has_arg = has_arg self.has_arg = has_arg
self.attr = attr self.attr = attr
self.pattr = pattr self.pattr = pattr
self.optype = optype
if has_extended_arg: if has_extended_arg:
self.offset = "%d_%d" % (offset, offset + 2) self.offset = "%d_%d" % (offset, offset + 2)
else: else:
@@ -109,7 +111,7 @@ class Token: # Python 2.4 can't have empty ()
self.op = op self.op = op
def __eq__(self, o): def __eq__(self, o):
""" '==' on kind and "pattr" attributes. """'==' on kind and "pattr" attributes.
It is okay if offsets and linestarts are different""" It is okay if offsets and linestarts are different"""
if isinstance(o, Token): if isinstance(o, Token):
return (self.kind == o.kind) and ( return (self.kind == o.kind) and (
@@ -120,7 +122,7 @@ class Token: # Python 2.4 can't have empty ()
return self.kind == o return self.kind == o
def __ne__(self, o): def __ne__(self, o):
""" '!=', but it's okay if offsets and linestarts are different""" """'!=', but it's okay if offsets and linestarts are different"""
return not self.__eq__(o) return not self.__eq__(o)
def __repr__(self): def __repr__(self):

View File

@@ -135,7 +135,7 @@ ASSIGN_DOC_STRING = lambda doc_string, doc_load: SyntaxTree(
SyntaxTree( SyntaxTree(
"expr", [Token(doc_load, pattr=doc_string, attr=doc_string)] "expr", [Token(doc_load, pattr=doc_string, attr=doc_string)]
), ),
SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__")]), SyntaxTree("store", [Token("STORE_NAME", pattr="__doc__", optype="name")]),
], ],
) )
@@ -147,10 +147,10 @@ NAME_MODULE = SyntaxTree(
"assign", "assign",
[ [
SyntaxTree( SyntaxTree(
"expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True)] "expr", [Token("LOAD_NAME", pattr="__name__", offset=0, has_arg=True, optype="name")]
), ),
SyntaxTree( SyntaxTree(
"store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True)] "store", [Token("STORE_NAME", pattr="__module__", offset=3, has_arg=True, optype="name")]
), ),
], ],
) )

View File

@@ -17,20 +17,26 @@
All the crazy things we have to do to handle Python functions in Python before 3.0. All the crazy things we have to do to handle Python functions in Python before 3.0.
The saga of changes continues in 3.0 and above and in other files. The saga of changes continues in 3.0 and above and in other files.
""" """
from uncompyle6.scanner import Code from itertools import zip_longest
from uncompyle6.semantics.parser_error import ParserError
from xdis import code_has_star_arg, code_has_star_star_arg, iscode
from uncompyle6.parser import ParserError as ParserError2 from uncompyle6.parser import ParserError as ParserError2
from uncompyle6.scanner import Code
from uncompyle6.semantics.helper import ( from uncompyle6.semantics.helper import (
print_docstring,
find_all_globals, find_all_globals,
find_globals_and_nonlocals, find_globals_and_nonlocals,
find_none, find_none,
print_docstring,
zip_longest zip_longest
) )
from xdis import iscode, code_has_star_arg, code_has_star_star_arg from xdis import iscode, code_has_star_arg, code_has_star_star_arg
)
from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.show import maybe_show_tree_param_default from uncompyle6.show import maybe_show_tree_param_default
def make_function2(self, node, is_lambda, nested=1, code_node=None): def make_function2(self, node, is_lambda, nested=1, code_node=None):
""" """
Dump function definition, doc string, and function body. Dump function definition, doc string, and function body.
@@ -51,7 +57,6 @@ def make_function2(self, node, is_lambda, nested=1, code_node=None):
if default: if default:
value = self.traverse(default, indent="") value = self.traverse(default, indent="")
maybe_show_tree_param_default(self.showast, name, value)
result = "%s=%s" % (name, value) result = "%s=%s" % (name, value)
if result[-2:] == "= ": # default was 'LOAD_CONST None' if result[-2:] == "= ": # default was 'LOAD_CONST None'
result += "None" result += "None"

View File

@@ -340,7 +340,6 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
- handle format tuple parameters - handle format tuple parameters
""" """
value = self.traverse(default, indent="") value = self.traverse(default, indent="")
maybe_show_tree_param_default(self.showast, name, value)
if annotation: if annotation:
result = "%s: %s=%s" % (name, annotation, value) result = "%s: %s=%s" % (name, annotation, value)
else: else:

View File

@@ -17,23 +17,22 @@ All the crazy things we have to do to handle Python functions in 3.6 and above.
The saga of changes before 3.6 is in other files. The saga of changes before 3.6 is in other files.
""" """
from xdis import ( from xdis import (
iscode, CO_ASYNC_GENERATOR,
CO_GENERATOR,
code_has_star_arg, code_has_star_arg,
code_has_star_star_arg, code_has_star_star_arg,
CO_GENERATOR, iscode,
CO_ASYNC_GENERATOR,
) )
from uncompyle6.scanner import Code
from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.parser import ParserError as ParserError2 from uncompyle6.parser import ParserError as ParserError2
from uncompyle6.scanner import Code
from uncompyle6.semantics.helper import ( from uncompyle6.semantics.helper import (
find_all_globals, find_all_globals,
find_globals_and_nonlocals, find_globals_and_nonlocals,
find_none, find_none,
zip_longest zip_longest
) )
from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.show import maybe_show_tree_param_default
def make_function36(self, node, is_lambda, nested=1, code_node=None): def make_function36(self, node, is_lambda, nested=1, code_node=None):
@@ -56,7 +55,6 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
- handle format tuple parameters - handle format tuple parameters
""" """
value = default value = default
maybe_show_tree_param_default(self.showast, name, value)
if annotation: if annotation:
result = "%s: %s=%s" % (name, annotation, value) result = "%s: %s=%s" % (name, annotation, value)
else: else:
@@ -151,7 +149,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
kwonlyargcount = code.co_kwonlyargcount kwonlyargcount = code.co_kwonlyargcount
paramnames = list(scanner_code.co_varnames[:argc]) paramnames = list(scanner_code.co_varnames[:argc])
kwargs = list(scanner_code.co_varnames[argc: argc + kwonlyargcount]) kwargs = list(scanner_code.co_varnames[argc : argc + kwonlyargcount])
paramnames.reverse() paramnames.reverse()
defparams.reverse() defparams.reverse()
@@ -182,7 +180,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
) )
) )
for param in paramnames[i + 1:]: for param in paramnames[i + 1 :]:
if param in annotate_dict: if param in annotate_dict:
params.append("%s: %s" % (param, annotate_dict[param])) params.append("%s: %s" % (param, annotate_dict[param]))
else: else:

View File

@@ -240,6 +240,11 @@ class NonterminalActions:
assert len(keys) == len(flat_elems) - 1 assert len(keys) == len(flat_elems) - 1
for i, elem in enumerate(flat_elems[:-1]): for i, elem in enumerate(flat_elems[:-1]):
assert elem.kind == "ADD_VALUE" assert elem.kind == "ADD_VALUE"
if elem.optype in ("local", "name"):
value = elem.attr
elif elem.optype == "const" and not isinstance(elem.attr, str):
value = elem.attr
else:
try: try:
value = "%r" % elem.pattr value = "%r" % elem.pattr
except Exception: except Exception:
@@ -266,11 +271,15 @@ class NonterminalActions:
for elem in flat_elems: for elem in flat_elems:
if elem == "add_value": if elem == "add_value":
elem = elem[0] elem = elem[0]
if elem == "ADD_VALUE": if elem == "ADD_VALUE":
if self.version < (3, 0, 0): if elem.optype in ("local", "name"):
value = "%s" % repr(elem.pattr) value = elem.attr
elif elem.optype == "const" and not isinstance(elem.attr, str):
value = elem.attr
>>>>>>> python-3.0-to-3.2
else: else:
value = "%s" % str(elem.pattr) value = "%s" % repr(elem.attr)
else: else:
assert elem.kind == "ADD_VALUE_VAR" assert elem.kind == "ADD_VALUE_VAR"
value = "%s" % elem.pattr value = "%s" % elem.pattr