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=(
[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_collections.py]=1
[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_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

View File

@@ -1,6 +1,6 @@
SKIP_TESTS=(
[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_ftplib.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_buffer.py]=1 # parse error
[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_script.py]=1
[test_compileall.py]=1 # fails on its own

View File

@@ -69,7 +69,7 @@ SKIP_TESTS=(
[test_cgi.py]=1 # parse error
[test_cgitb.py]=1 # parse error
[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_line.py]=1 # Interactive?
[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
for file in $files; do
if (( SKIP_TESTS[$file] != "pytest" )); then
SKIP_TESTS[$file] = 1;
SKIP_TESTS[$file]=1;
fi
done
fi

View File

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

View File

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

View File

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

View File

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

View File

@@ -135,7 +135,7 @@ ASSIGN_DOC_STRING = lambda doc_string, doc_load: SyntaxTree(
SyntaxTree(
"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",
[
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(
"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.
The saga of changes continues in 3.0 and above and in other files.
"""
from uncompyle6.scanner import Code
from uncompyle6.semantics.parser_error import ParserError
from itertools import zip_longest
from xdis import code_has_star_arg, code_has_star_star_arg, iscode
from uncompyle6.parser import ParserError as ParserError2
from uncompyle6.scanner import Code
from uncompyle6.semantics.helper import (
print_docstring,
find_all_globals,
find_globals_and_nonlocals,
find_none,
print_docstring,
zip_longest
)
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
def make_function2(self, node, is_lambda, nested=1, code_node=None):
"""
Dump function definition, doc string, and function body.
@@ -39,8 +45,8 @@ def make_function2(self, node, is_lambda, nested=1, code_node=None):
def build_param(ast, name, default):
"""build parameters:
- handle defaults
- handle format tuple parameters
- handle defaults
- handle format tuple parameters
"""
# if formal parameter is a tuple, the paramater name
# starts with a dot (eg. '.1', '.2')
@@ -51,7 +57,6 @@ def make_function2(self, node, is_lambda, nested=1, code_node=None):
if default:
value = self.traverse(default, indent="")
maybe_show_tree_param_default(self.showast, name, value)
result = "%s=%s" % (name, value)
if result[-2:] == "= ": # default was 'LOAD_CONST None'
result += "None"
@@ -198,5 +203,5 @@ def make_function2(self, node, is_lambda, nested=1, code_node=None):
ast, code.co_name, code._customize, is_lambda=is_lambda, returnNone=rn
)
code._tokens = None # save memory
code._tokens = None # save memory
code._customize = None # save memory

View File

@@ -340,7 +340,6 @@ def make_function3(self, node, is_lambda, nested=1, code_node=None):
- handle format tuple parameters
"""
value = self.traverse(default, indent="")
maybe_show_tree_param_default(self.showast, name, value)
if annotation:
result = "%s: %s=%s" % (name, annotation, value)
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.
"""
from xdis import (
iscode,
CO_ASYNC_GENERATOR,
CO_GENERATOR,
code_has_star_arg,
code_has_star_star_arg,
CO_GENERATOR,
CO_ASYNC_GENERATOR,
iscode,
)
from uncompyle6.scanner import Code
from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.parser import ParserError as ParserError2
from uncompyle6.scanner import Code
from uncompyle6.semantics.helper import (
find_all_globals,
find_globals_and_nonlocals,
find_none,
zip_longest
)
from uncompyle6.show import maybe_show_tree_param_default
from uncompyle6.semantics.parser_error import ParserError
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
"""
value = default
maybe_show_tree_param_default(self.showast, name, value)
if annotation:
result = "%s: %s=%s" % (name, annotation, value)
else:
@@ -151,7 +149,7 @@ def make_function36(self, node, is_lambda, nested=1, code_node=None):
kwonlyargcount = code.co_kwonlyargcount
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()
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:
params.append("%s: %s" % (param, annotate_dict[param]))
else:

View File

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