Skip to content

Commit 6ec063c

Browse files
committed
Revise for newer xdis API
1 parent 3d53b64 commit 6ec063c

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

uncompyle6/scanner.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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
@@ -37,7 +37,8 @@
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

4243
from uncompyle6.scanners.tok import Token
4344

@@ -111,25 +112,22 @@ def __init__(self, co, scanner, classname=None, show_asm=None):
111112

112113

113114
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
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

@@ -198,7 +196,7 @@ def bound_collection_from_tokens(self, tokens, t, i, collection_type):
198196
linestart=tokens[j].linestart,
199197
opc=self.opc,
200198
has_extended_arg=False,
201-
optype=op_type
199+
optype=op_type,
202200
)
203201
)
204202
new_tokens.append(

uncompyle6/scanners/scanner3.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015-2019, 2021-2024 by Rocky Bernstein
1+
# Copyright (c) 2015-2019, 2021-2024, 2026 by Rocky Bernstein
22
# Copyright (c) 2005 by Dan Pascu <[email protected]>
33
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
44
#
@@ -39,12 +39,12 @@
3939
from typing import Optional, Tuple
4040

4141
import xdis
42-
43-
# Get all the opcodes into globals
44-
import xdis.opcodes.opcode_33 as op3
4542
from xdis import Instruction, instruction_size, iscode
4643
from xdis.bytecode import _get_const_info
47-
from xdis.opcodes.opcode_3x import parse_fn_counts_30_35
44+
45+
# Get all the opcodes into globals
46+
from xdis.opcodes import opcode_33 as op3
47+
from xdis.opcodes.opcode_3x.opcode_3x import parse_fn_counts_30_35
4848

4949
from uncompyle6.scanner import CONST_COLLECTIONS, Scanner
5050
from uncompyle6.scanners.tok import Token

uncompyle6/scanners/scanner37base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015-2020, 2022-2024 by Rocky Bernstein
1+
# Copyright (c) 2015-2020, 2022-2024, 2026 by Rocky Bernstein
22
# Copyright (c) 2005 by Dan Pascu <[email protected]>
33
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
44
#
@@ -33,12 +33,12 @@
3333
from typing import Any, Dict, List, Set, Tuple
3434

3535
import xdis
36-
37-
# Get all the opcodes into globals
38-
import xdis.opcodes.opcode_37 as op3
3936
from xdis import Instruction, instruction_size, iscode
4037
from xdis.bytecode import _get_const_info
4138

39+
# Get all the opcodes into globals
40+
from xdis.opcodes import opcode_37 as op3
41+
4242
from uncompyle6.scanner import Scanner, Token
4343

4444
globals().update(op3.opmap)

0 commit comments

Comments
 (0)