You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Merge branch 'master' into python-2.4
This commit is contained in:
Binary file not shown.
Binary file not shown.
42
test/simple_source/bug37/02_and_or.py
Normal file
42
test/simple_source/bug37/02_and_or.py
Normal 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}"
|
25
test/simple_source/bug37/03_jump_to_jump.py
Normal file
25
test/simple_source/bug37/03_jump_to_jump.py
Normal 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
|
@@ -15,3 +15,11 @@ class BZ2File(io.BufferedIOBase):
|
||||
|
||||
class ABC(metaclass=BZ2File):
|
||||
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)
|
||||
|
@@ -26,7 +26,7 @@ FULLVERSION=$(pyenv local)
|
||||
PYVERSION=${FULLVERSION%.*}
|
||||
MINOR=${FULLVERSION##?.?.}
|
||||
|
||||
typeset -i STOP_ONERROR=1
|
||||
STOP_ONERROR=${STOP_ONERROR:-1}
|
||||
|
||||
typeset -A SKIP_TESTS
|
||||
case $PYVERSION in
|
||||
@@ -182,11 +182,15 @@ TESTDIR=/tmp/test${PYVERSION}
|
||||
if [[ -e $TESTDIR ]] ; then
|
||||
rm -fr $TESTDIR
|
||||
fi
|
||||
|
||||
PYENV_ROOT=${PYENV_ROOT:-$HOME/.pyenv}
|
||||
pyenv_local=$(pyenv local)
|
||||
mkdir $TESTDIR || exit $?
|
||||
cp -r ${PYENV_ROOT}/versions/${PYVERSION}.${MINOR}/lib/python${PYVERSION}/test $TESTDIR
|
||||
cd $TESTDIR/test
|
||||
pyenv local $FULLVERSION
|
||||
export PYTHONPATH=$TESTDIR
|
||||
export PATH=${PYENV_ROOT}/shims:${PATH}
|
||||
|
||||
# Run tests
|
||||
typeset -i i=0
|
||||
@@ -198,7 +202,7 @@ if [[ -n $1 ]] ; then
|
||||
SKIP_TESTS=()
|
||||
fi
|
||||
else
|
||||
files=test_*.py
|
||||
files=$(echo test_*.py)
|
||||
fi
|
||||
|
||||
typeset -i ALL_FILES_STARTTIME=$(date +%s)
|
||||
|
@@ -70,4 +70,6 @@ def customize_for_version37(self, version):
|
||||
'testfalse_not_or': ( "not %c or %c",
|
||||
(0, "expr"),
|
||||
(2, "expr") ),
|
||||
'testfalse_not_and': ( "not (%c)", 0 ),
|
||||
|
||||
})
|
||||
|
@@ -1630,7 +1630,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
pass
|
||||
pass
|
||||
else:
|
||||
if self.version >= 3.6 and node[0] == "LOAD_CONST":
|
||||
if node[0] == "LOAD_STR":
|
||||
return
|
||||
value = self.traverse(node[0])
|
||||
self.write("(")
|
||||
|
@@ -243,9 +243,7 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
)
|
||||
node[3] = elifelse_stmt
|
||||
else:
|
||||
elif_stmt = SyntaxTree(
|
||||
"elifstmt", [n[0], n[else_suite_index]]
|
||||
)
|
||||
elif_stmt = SyntaxTree("elifstmt", [n[0], n[else_suite_index]])
|
||||
node[3] = elif_stmt
|
||||
|
||||
node.transformed_by = "n_ifelsestmt"
|
||||
@@ -260,11 +258,11 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
|
||||
def n_list_for(self, list_for_node):
|
||||
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
|
||||
assert expr[0][0] == "expr"
|
||||
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
|
||||
|
||||
def traverse(self, node, is_lambda=False):
|
||||
|
Reference in New Issue
Block a user