Merge branch 'master' into python-2.4

This commit is contained in:
rocky
2019-12-15 10:51:34 -05:00
9 changed files with 87 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,42 @@
# from 3.7 decompyle3/pytest/validate.py
# 3.7 changes changes "and" to use JUMP_IF_FALSE_OR_POP instead of
# POP_JUMP_IF_FALSE
# RUNNABLE!
def are_instructions_equal(a, b, c, d):
return a and (b or c) and d
for a, b, c, d, expect in (
(True, True, False, True, True),
(True, False, True, True, True),
(False, False, True, True, False),
(True, False, True, False, False),
):
assert are_instructions_equal(a, b, c, d) == expect
# FIXME: figure out how to fix properly, and test.
# from 3.7 decompyle3/semantics/pysource.py
# Bug *is* miscompiling to
# if a:
# if b or c:
# d = 1
# else:
# d = 2
def n_alias(a, b, c, d=3):
if a and b or c:
d = 1
else:
d = 2
return d
for a, b, c, expect in (
(True, True, False, 1),
(True, False, True, 1),
# (True, False, False, 2), # miscompiles
# (False, False, True, 1), # miscompiles
(False, False, False, 2),
):
assert n_alias(a, b, c) == expect, f"{a}, {b}, {c}, {expect}"

View File

@@ -0,0 +1,25 @@
# From uncompyle6/verify.py
# Bug was POP_JUMP offset to short so we have a POP_JUMP
# to a JUMP_ABSOULTE and this messes up reduction rule checking.
def cmp_code_objects(member, a, tokens1, tokens2, verify, f):
for member in members:
while a:
# Increase the bytecode length of the while statement
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
x = 1; x = 2; x = 3; x = 4; x = 5; x = 6; x = 7; x = 8
x = 49; x = 50; x = 51; x = 52; x = 53;
if tokens1:
if tokens2:
continue
elif f:
continue
else:
a = 2
i1 += 1
x = 54 # comment this out and we're good

View File

@@ -15,3 +15,11 @@ class BZ2File(io.BufferedIOBase):
class ABC(metaclass=BZ2File): class ABC(metaclass=BZ2File):
pass pass
# From 3.3 test_abc
# Bug was class Descriptor("Descriptor"): instead of below
def test_customdescriptors_with_abstractmethod():
class Descriptor:
def setter(self):
return Descriptor(self._fget)

View File

@@ -26,7 +26,7 @@ FULLVERSION=$(pyenv local)
PYVERSION=${FULLVERSION%.*} PYVERSION=${FULLVERSION%.*}
MINOR=${FULLVERSION##?.?.} MINOR=${FULLVERSION##?.?.}
typeset -i STOP_ONERROR=1 STOP_ONERROR=${STOP_ONERROR:-1}
typeset -A SKIP_TESTS typeset -A SKIP_TESTS
case $PYVERSION in case $PYVERSION in
@@ -182,11 +182,15 @@ TESTDIR=/tmp/test${PYVERSION}
if [[ -e $TESTDIR ]] ; then if [[ -e $TESTDIR ]] ; then
rm -fr $TESTDIR rm -fr $TESTDIR
fi fi
PYENV_ROOT=${PYENV_ROOT:-$HOME/.pyenv}
pyenv_local=$(pyenv local)
mkdir $TESTDIR || exit $? mkdir $TESTDIR || exit $?
cp -r ${PYENV_ROOT}/versions/${PYVERSION}.${MINOR}/lib/python${PYVERSION}/test $TESTDIR cp -r ${PYENV_ROOT}/versions/${PYVERSION}.${MINOR}/lib/python${PYVERSION}/test $TESTDIR
cd $TESTDIR/test cd $TESTDIR/test
pyenv local $FULLVERSION pyenv local $FULLVERSION
export PYTHONPATH=$TESTDIR export PYTHONPATH=$TESTDIR
export PATH=${PYENV_ROOT}/shims:${PATH}
# Run tests # Run tests
typeset -i i=0 typeset -i i=0
@@ -198,7 +202,7 @@ if [[ -n $1 ]] ; then
SKIP_TESTS=() SKIP_TESTS=()
fi fi
else else
files=test_*.py files=$(echo test_*.py)
fi fi
typeset -i ALL_FILES_STARTTIME=$(date +%s) typeset -i ALL_FILES_STARTTIME=$(date +%s)

View File

@@ -70,4 +70,6 @@ def customize_for_version37(self, version):
'testfalse_not_or': ( "not %c or %c", 'testfalse_not_or': ( "not %c or %c",
(0, "expr"), (0, "expr"),
(2, "expr") ), (2, "expr") ),
'testfalse_not_and': ( "not (%c)", 0 ),
}) })

View File

@@ -1630,7 +1630,7 @@ class SourceWalker(GenericASTTraversal, object):
pass pass
pass pass
else: else:
if self.version >= 3.6 and node[0] == "LOAD_CONST": if node[0] == "LOAD_STR":
return return
value = self.traverse(node[0]) value = self.traverse(node[0])
self.write("(") self.write("(")

View File

@@ -243,9 +243,7 @@ class TreeTransform(GenericASTTraversal, object):
) )
node[3] = elifelse_stmt node[3] = elifelse_stmt
else: else:
elif_stmt = SyntaxTree( elif_stmt = SyntaxTree("elifstmt", [n[0], n[else_suite_index]])
"elifstmt", [n[0], n[else_suite_index]]
)
node[3] = elif_stmt node[3] = elif_stmt
node.transformed_by = "n_ifelsestmt" node.transformed_by = "n_ifelsestmt"
@@ -260,11 +258,11 @@ class TreeTransform(GenericASTTraversal, object):
def n_list_for(self, list_for_node): def n_list_for(self, list_for_node):
expr = list_for_node[0] expr = list_for_node[0]
if (expr == "expr" and expr[0] == "get_iter"): if expr == "expr" and expr[0] == "get_iter":
# Remove extraneous get_iter() inside the "for" of a comprehension # Remove extraneous get_iter() inside the "for" of a comprehension
assert expr[0][0] == "expr" assert expr[0][0] == "expr"
list_for_node[0] = expr[0][0] list_for_node[0] = expr[0][0]
list_for_node.transformed_by="n_list_for", list_for_node.transformed_by = ("n_list_for",)
return list_for_node return list_for_node
def traverse(self, node, is_lambda=False): def traverse(self, node, is_lambda=False):