|
1 | | -# Copyright (c) 2016, 2018-2025 by Rocky Bernstein |
| 1 | +# Copyright (c) 2016, 2018-2026 by Rocky Bernstein |
2 | 2 | # Copyright (c) 2005 by Dan Pascu <[email protected]> |
3 | 3 | # Copyright (c) 2000-2002 by hartmut Goebel <[email protected]> |
4 | 4 | # Copyright (c) 1999 John Aycock |
|
37 | 37 | instruction_size, |
38 | 38 | next_offset, |
39 | 39 | ) |
40 | | -from xdis.version_info import IS_PYPY, version_tuple_to_str |
| 40 | +from xdis.op_imports import get_opcode_module |
| 41 | +from xdis.version_info import IS_PYPY, PythonImplementation, version_tuple_to_str |
41 | 42 |
|
42 | 43 | from uncompyle6.scanners.tok import Token |
43 | 44 |
|
@@ -111,25 +112,22 @@ def __init__(self, co, scanner, classname=None, show_asm=None): |
111 | 112 |
|
112 | 113 |
|
113 | 114 | class Scanner(ABC): |
114 | | - def __init__(self, version: tuple, show_asm=None, is_pypy=False): |
115 | | - self.version = version |
| 115 | + def __init__(self, version_tuple: tuple, show_asm=None, is_pypy=False): |
| 116 | + self.version = version_tuple |
116 | 117 | self.show_asm = show_asm |
117 | 118 | self.is_pypy = is_pypy |
118 | 119 |
|
119 | 120 | # Temporary initialization. |
120 | 121 | self.opc = ModuleType("uninitialized") |
121 | 122 |
|
122 | | - if version[:2] in PYTHON_VERSIONS: |
123 | | - v_str = f"""opcode_{version_tuple_to_str(version, start=0, end=2, delimiter="")}""" |
124 | | - module_name = f"xdis.opcodes.{v_str}" |
125 | | - if is_pypy: |
126 | | - module_name += "pypy" |
127 | | - self.opc = importlib.import_module(module_name) |
128 | | - else: |
129 | | - raise TypeError( |
130 | | - "%s is not a Python version I know about" |
131 | | - % version_tuple_to_str(version) |
| 123 | + if version_tuple[:2] in PYTHON_VERSIONS: |
| 124 | + v_str = f"""opcode_{version_tuple_to_str(version_tuple, start=0, end=2, delimiter="")}""" |
| 125 | + python_implementation = ( |
| 126 | + PythonImplementation.PyPy if is_pypy else PythonImplementation.CPython |
132 | 127 | ) |
| 128 | + self.opc = get_opcode_module(version_tuple, python_implementation) |
| 129 | + else: |
| 130 | + raise TypeError("%s is not a Python version I know about" % v_str(version)) |
133 | 131 |
|
134 | 132 | self.opname = self.opc.opname |
135 | 133 |
|
@@ -198,7 +196,7 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type): |
198 | 196 | linestart=tokens[j].linestart, |
199 | 197 | opc=self.opc, |
200 | 198 | has_extended_arg=False, |
201 | | - optype=op_type |
| 199 | + optype=op_type, |
202 | 200 | ) |
203 | 201 | ) |
204 | 202 | new_tokens.append( |
|
0 commit comments