DRY using version_info_to_str

This commit is contained in:
rocky 2021-10-23 08:24:35 -04:00
parent 0a9dc57cc9
commit e3369edaed
4 changed files with 9 additions and 14 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY
from xdis.version_info import PYTHON_VERSION_TRIPLE, IS_PYPY, version_tuple_to_str
from uncompyle6.scanner import get_scanner
def bug(state, slotstate):
if state:
@ -62,6 +62,6 @@ def test_if_in_for():
{'end': 59, 'type': 'for-loop', 'start': 31},
{'end': 63, 'type': 'for-else', 'start': 62}]
else:
print("FIXME: should fix for %s" % ".".join([str(v) for v in PYTHON_VERSION_TRIPLE]))
print("FIXME: should fix for %s" % version_tuple_to_str())
assert True
return

View File

@ -29,12 +29,11 @@ Second, we need structured instruction information for the
want to run on earlier Python versions.
"""
from __future__ import print_function
import sys
from collections import deque
from xdis import check_object_path, iscode, load_module
from xdis.version_info import version_tuple_to_str
from uncompyle6.scanner import get_scanner
@ -47,7 +46,7 @@ def disco(version, co, out=None, is_pypy=False):
# store final output stream for case of error
real_out = out or sys.stdout
print("# Python %s" % ".".join([str(v) for v in version]), file=real_out)
print("# Python %s" % version_tuple_to_str(version), file=real_out)
if co.co_filename:
print("# Embedded file name: %s" % co.co_filename, file=real_out)

View File

@ -21,14 +21,12 @@ scanner/ingestion module. From here we call various version-specific
scanners, e.g. for Python 2.7 or 3.4.
"""
from __future__ import print_function
from array import array
from collections import namedtuple
import sys
from uncompyle6 import PYTHON3, IS_PYPY
from uncompyle6.scanners.tok import Token
from xdis.version_info import PYTHON3, IS_PYPY, version_tuple_to_str
import xdis
from xdis import Bytecode, canonic_python_version, code2num, instruction_size, extended_arg_val, next_offset
@ -62,7 +60,7 @@ PYTHON_VERSIONS = frozenset(
)
CANONIC2VERSION = dict(
(canonic_python_version[".".join(str(v) for v in python_version)], python_version)
(canonic_python_version[version_tuple_to_str(python_version)], python_version)
for python_version in PYTHON_VERSIONS
)
@ -113,7 +111,7 @@ class Scanner(object):
exec("from xdis.opcodes import %s" % v_str)
exec("self.opc = %s" % v_str)
else:
raise TypeError("%s is not a Python version I know about" % ".".join([str(v) for v in version]))
raise TypeError("%s is not a Python version I know about" % version_tuple_to_str(version))
self.opname = self.opc.opname

View File

@ -7,11 +7,9 @@ grammar parsing.
"""
from __future__ import print_function
from uncompyle6.scanners.scanner2 import Scanner2
from uncompyle6 import PYTHON3
from xdis.version_info import PYTHON3, version_tuple_to_str
if PYTHON3:
import sys
@ -123,4 +121,4 @@ if __name__ == "__main__":
print(t)
pass
else:
print("Need to be Python 2.7 to demo; I am %s." % ".".join(str(v) for v in PYTHON_VERSION_TRIPLE))
print("Need to be Python 2.7 to demo; I am %s." % version_tuple_to_str())