1- # Copyright (c) 2016, 2018-2025 by Rocky Bernstein
1+ # Copyright (c) 2016, 2018-2026 by Rocky Bernstein
22# Copyright (c) 2005 by Dan Pascu <[email protected] > 33# Copyright (c) 2000-2002 by hartmut Goebel <[email protected] > 44# Copyright (c) 1999 John Aycock
3737 instruction_size ,
3838 next_offset ,
3939)
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
4142
4243from uncompyle6 .scanners .tok import Token
4344
@@ -111,25 +112,22 @@ def __init__(self, co, scanner, classname=None, show_asm=None):
111112
112113
113114class 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
116117 self .show_asm = show_asm
117118 self .is_pypy = is_pypy
118119
119120 # Temporary initialization.
120121 self .opc = ModuleType ("uninitialized" )
121122
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
132127 )
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 ))
133131
134132 self .opname = self .opc .opname
135133
@@ -184,8 +182,10 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type):
184182 for j in range (collection_start , i ):
185183 if tokens [j ] == "LOAD_CONST" :
186184 opname = "ADD_VALUE"
185+ op_type = "const"
187186 else :
188187 opname = "ADD_VALUE_VAR"
188+ op_type = "name"
189189 new_tokens .append (
190190 Token (
191191 opname = opname ,
@@ -196,6 +196,7 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type):
196196 linestart = tokens [j ].linestart ,
197197 opc = self .opc ,
198198 has_extended_arg = False ,
199+ optype = op_type ,
199200 )
200201 )
201202 new_tokens .append (
@@ -208,6 +209,7 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type):
208209 linestart = t .linestart ,
209210 opc = t .opc ,
210211 has_extended_arg = False ,
212+ optype = "vargs" ,
211213 )
212214 )
213215 return new_tokens
0 commit comments