From ed34bf9d4a415de15f1ea033da168ddfa121d456 Mon Sep 17 00:00:00 2001 From: rocky Date: Tue, 2 Nov 2021 06:16:26 -0400 Subject: [PATCH] use xdis.PYTHON3 not uncompyle.PYTHON3 --- pytest/test_deparse.py | 7 ++----- pytest/test_pysource.py-notyet | 2 +- pytest/test_single_compile.py | 7 ++++--- test/Makefile | 4 ++-- test/test_pythonlib.py | 4 ++-- uncompyle6/__init__.py | 17 +++-------------- uncompyle6/parsers/treenode.py | 2 +- uncompyle6/scanners/scanner2.py | 2 +- uncompyle6/scanners/scanner26.py | 2 +- uncompyle6/scanners/scanner3.py | 2 +- uncompyle6/scanners/tok.py | 4 ++-- uncompyle6/semantics/consts.py | 2 +- uncompyle6/semantics/helper.py | 2 +- uncompyle6/semantics/make_function2.py | 4 ++-- uncompyle6/semantics/make_function36.py | 4 +--- uncompyle6/util.py | 2 +- uncompyle6/verify.py | 2 +- 17 files changed, 27 insertions(+), 42 deletions(-) diff --git a/pytest/test_deparse.py b/pytest/test_deparse.py index cfa080ff..50f02aff 100644 --- a/pytest/test_deparse.py +++ b/pytest/test_deparse.py @@ -1,6 +1,5 @@ -import pytest -from uncompyle6.semantics.fragments import code_deparse as deparse, deparsed_find -from uncompyle6 import PYTHON_VERSION, PYTHON3 +from uncompyle6.semantics.fragments import code_deparse as deparse +from xdis.version_info import PYTHON_VERSION, PYTHON3 def map_stmts(x, y): x = [] @@ -37,13 +36,11 @@ def check_expect(expect, parsed, fn_name): debug = False i = 2 max_expect = len(expect) - code = get_parsed_for_fn(fn_name) for name, offset in sorted(parsed.offsets.keys()): assert i+1 <= max_expect, ( "%s: ran out if items in testing node" % fn_name) nodeInfo = parsed.offsets[name, offset] node = nodeInfo.node - nodeInfo2 = deparsed_find((name, offset), parsed, code) extractInfo = parsed.extract_node_info(node) assert expect[i] == extractInfo.selectedLine, \ diff --git a/pytest/test_pysource.py-notyet b/pytest/test_pysource.py-notyet index e64df27c..cdb9ef06 100644 --- a/pytest/test_pysource.py-notyet +++ b/pytest/test_pysource.py-notyet @@ -1,11 +1,11 @@ import sys -from uncompyle6 import PYTHON3 from uncompyle6.scanner import get_scanner from uncompyle6.semantics.consts import ( escape, NONE, # RETURN_NONE, PASS, RETURN_LOCALS ) +from xdis.version_info import PYTHON3 if PYTHON3: from io import StringIO def iteritems(d): diff --git a/pytest/test_single_compile.py b/pytest/test_single_compile.py index b5d6b1f2..2820bec4 100644 --- a/pytest/test_single_compile.py +++ b/pytest/test_single_compile.py @@ -1,9 +1,10 @@ import pytest -from uncompyle6 import PYTHON_VERSION, code_deparse -pytestmark = pytest.mark.skip(PYTHON_VERSION < 2.7, +from uncompyle6 import code_deparse +from xdis.version_info import PYTHON_VERSION_TRIPLE +pytestmark = pytest.mark.skip(PYTHON_VERSION_TRIPLE < (2, 7), reason="need at least Python 2.7") -if PYTHON_VERSION > 2.6: +if PYTHON_VERSION_TRIPLE > (2, 6): def test_single_mode(): single_expressions = ( 'i = 1', diff --git a/test/Makefile b/test/Makefile index 50af03a7..6857e0cf 100644 --- a/test/Makefile +++ b/test/Makefile @@ -84,8 +84,8 @@ check-3.10: check-bytecode @echo "Note that we do not support decompiling Python 3.10 bytecode - no 3.10 tests run" # FIXME -#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, or pypy3.6-7.3.0 -5.8 5.6: +#: this is called when running under pypy3.5-5.8.0, pypy2-5.6.0, pypy3.6-7.3.0 or pypy3.8-7.3.7 +5.8 5.6 7.3: #: Check deparsing only, but from a different Python version check-disasm: diff --git a/test/test_pythonlib.py b/test/test_pythonlib.py index 715b6e92..a45e392b 100755 --- a/test/test_pythonlib.py +++ b/test/test_pythonlib.py @@ -31,9 +31,9 @@ from __future__ import print_function import getopt, os, py_compile, sys, shutil, tempfile, time -from uncompyle6 import PYTHON_VERSION -from uncompyle6.main import main from fnmatch import fnmatch +from uncompyle6.main import main +from xdis.version_info import PYTHON_VERSION def get_srcdir(): diff --git a/uncompyle6/__init__.py b/uncompyle6/__init__.py index 90eb5df0..a6357e46 100644 --- a/uncompyle6/__init__.py +++ b/uncompyle6/__init__.py @@ -1,5 +1,5 @@ """ - Copyright (c) 2015, 2018 by Rocky Bernstein + Copyright (c) 2015, 2018, 2021 by Rocky Bernstein Copyright (c) 2000 by hartmut Goebel Copyright (c) 1999 John Aycock @@ -30,18 +30,7 @@ import sys __docformat__ = "restructuredtext" -from uncompyle6.version import __version__ - -PYTHON3 = sys.version_info >= (3, 0) - -# We do this crazy way to support Python 2.6 which -# doesn't support version_major, and has a bug in -# floating point so we can't divide 26 by 10 and get -# 2.6 -PYTHON_VERSION = sys.version_info[0] + (sys.version_info[1] / 10.0) -PYTHON_VERSION_STR = "%s.%s" % (sys.version_info[0], sys.version_info[1]) - -IS_PYPY = "__pypy__" in sys.builtin_module_names +from uncompyle6.version import __version__ # noqa if hasattr(sys, "setrecursionlimit"): # pyston doesn't have setrecursionlimit @@ -51,7 +40,7 @@ import uncompyle6.semantics.pysource import uncompyle6.semantics.fragments # Export some functions -from uncompyle6.main import decompile_file +from uncompyle6.main import decompile_file # noqa # Convenience functions so you can say: # from uncompyle6 import (code_deparse, deparse_code2str) diff --git a/uncompyle6/parsers/treenode.py b/uncompyle6/parsers/treenode.py index 4369393e..4fff2c31 100644 --- a/uncompyle6/parsers/treenode.py +++ b/uncompyle6/parsers/treenode.py @@ -1,5 +1,5 @@ import sys -from uncompyle6 import PYTHON3 +from xdis.version_info import PYTHON3 from uncompyle6.scanners.tok import NoneToken from spark_parser.ast import AST as spark_AST diff --git a/uncompyle6/scanners/scanner2.py b/uncompyle6/scanners/scanner2.py index f21a8edb..fccbf677 100644 --- a/uncompyle6/scanners/scanner2.py +++ b/uncompyle6/scanners/scanner2.py @@ -40,7 +40,7 @@ from copy import copy from xdis import code2num, iscode, op_has_argument, instruction_size from xdis.bytecode import _get_const_info -from uncompyle6 import PYTHON3 +from xdis.version_info import PYTHON3 if PYTHON3: from sys import intern diff --git a/uncompyle6/scanners/scanner26.py b/uncompyle6/scanners/scanner26.py index 9497c391..25b683f6 100755 --- a/uncompyle6/scanners/scanner26.py +++ b/uncompyle6/scanners/scanner26.py @@ -23,7 +23,7 @@ use in deparsing. """ import sys -from uncompyle6 import PYTHON3 +from xdis.version_info import PYTHON3 if PYTHON3: intern = sys.intern diff --git a/uncompyle6/scanners/scanner3.py b/uncompyle6/scanners/scanner3.py index aa89dd00..cc5745e5 100644 --- a/uncompyle6/scanners/scanner3.py +++ b/uncompyle6/scanners/scanner3.py @@ -47,7 +47,7 @@ import xdis.opcodes.opcode_33 as op3 from uncompyle6.scanner import Scanner import sys -from uncompyle6 import PYTHON3 +from xdis.version_info import PYTHON3 if PYTHON3: intern = sys.intern diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index 62a3d8d6..42723539 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2020 by Rocky Bernstein +# Copyright (c) 2016-2021 by Rocky Bernstein # Copyright (c) 2000-2002 by hartmut Goebel # Copyright (c) 1999 John Aycock # @@ -16,7 +16,7 @@ # along with this program. If not, see . import re, sys -from uncompyle6 import PYTHON3 +from xdis.version_info import PYTHON3 if PYTHON3: intern = sys.intern diff --git a/uncompyle6/semantics/consts.py b/uncompyle6/semantics/consts.py index 6d918338..07ccc7c3 100644 --- a/uncompyle6/semantics/consts.py +++ b/uncompyle6/semantics/consts.py @@ -16,8 +16,8 @@ import re, sys from uncompyle6.parsers.treenode import SyntaxTree -from uncompyle6 import PYTHON3 from uncompyle6.scanners.tok import Token, NoneToken +from xdis.version_info import PYTHON3 if PYTHON3: minint = -sys.maxsize - 1 diff --git a/uncompyle6/semantics/helper.py b/uncompyle6/semantics/helper.py index 03200229..392bd5f9 100644 --- a/uncompyle6/semantics/helper.py +++ b/uncompyle6/semantics/helper.py @@ -3,7 +3,7 @@ import sys from xdis import iscode from uncompyle6.parsers.treenode import SyntaxTree -from uncompyle6 import PYTHON3 +from xdis.version_info import PYTHON3 if PYTHON3: minint = -sys.maxsize-1 maxint = sys.maxsize diff --git a/uncompyle6/semantics/make_function2.py b/uncompyle6/semantics/make_function2.py index 85dd4a35..190abe2a 100644 --- a/uncompyle6/semantics/make_function2.py +++ b/uncompyle6/semantics/make_function2.py @@ -17,9 +17,7 @@ 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 xdis import iscode, code_has_star_arg, code_has_star_star_arg from uncompyle6.scanner import Code -from uncompyle6 import PYTHON3 from uncompyle6.semantics.parser_error import ParserError from uncompyle6.parser import ParserError as ParserError2 from uncompyle6.semantics.helper import ( @@ -28,6 +26,8 @@ from uncompyle6.semantics.helper import ( find_globals_and_nonlocals, find_none, ) +from xdis import iscode, code_has_star_arg, code_has_star_star_arg +from xdis.version_info import PYTHON3 if PYTHON3: from itertools import zip_longest diff --git a/uncompyle6/semantics/make_function36.py b/uncompyle6/semantics/make_function36.py index 8a2caddf..5124c5fc 100644 --- a/uncompyle6/semantics/make_function36.py +++ b/uncompyle6/semantics/make_function36.py @@ -24,16 +24,14 @@ from xdis import ( CO_ASYNC_GENERATOR, ) from uncompyle6.scanner import Code -from uncompyle6.parsers.treenode import SyntaxTree from uncompyle6.semantics.parser_error import ParserError from uncompyle6.parser import ParserError as ParserError2 -from uncompyle6 import PYTHON3 from uncompyle6.semantics.helper import ( - print_docstring, find_all_globals, find_globals_and_nonlocals, find_none, ) +from xdis.version_info import PYTHON3 if PYTHON3: from itertools import zip_longest diff --git a/uncompyle6/util.py b/uncompyle6/util.py index aeec12ed..6f01995b 100644 --- a/uncompyle6/util.py +++ b/uncompyle6/util.py @@ -3,7 +3,7 @@ # More could be done here though. from math import copysign -from uncompyle6 import PYTHON_VERSION +from xdis.version_info import PYTHON_VERSION def is_negative_zero(n): diff --git a/uncompyle6/verify.py b/uncompyle6/verify.py index 6d24e5d6..302c6036 100755 --- a/uncompyle6/verify.py +++ b/uncompyle6/verify.py @@ -26,8 +26,8 @@ from subprocess import call import uncompyle6 from uncompyle6.scanner import Token as ScannerToken, get_scanner -from uncompyle6 import PYTHON3 from xdis import iscode, load_file, load_module, pretty_code_flags, PYTHON_MAGIC_INT +from xdis.version_info import PYTHON3 # FIXME: DRY if PYTHON3: