Skip to content

Commit 7de3e44

Browse files
committed
Merge branch 'master' into python-3.6-to-3.10
2 parents 8a0eda1 + 6ec063c commit 7de3e44

File tree

6 files changed

+42
-30
lines changed

6 files changed

+42
-30
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ repos:
66
hooks:
77
- id: check-merge-conflict
88
- id: debug-statements
9-
stages: [commit]
9+
stages: [pre-commit]
1010
- id: end-of-file-fixer
11-
stages: [commit]
11+
stages: [pre-commit]
1212
- repo: https://github.com/pycqa/isort
1313
rev: 5.13.2
1414
hooks:

uncompyle6/scanner.py

Lines changed: 16 additions & 14 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

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

uncompyle6/scanners/scanner2.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2015-2024 by Rocky Bernstein
1+
# Copyright (c) 2015-2025 by Rocky Bernstein
22
# Copyright (c) 2005 by Dan Pascu <[email protected]>
33
# Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
44
#
@@ -39,7 +39,7 @@
3939
from sys import intern
4040

4141
from xdis import code2num, instruction_size, iscode, op_has_argument
42-
from xdis.bytecode import _get_const_info
42+
from xdis.bytecode import _get_const_info, get_optype
4343

4444
from uncompyle6.scanner import Scanner, Token
4545

@@ -304,6 +304,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
304304

305305
op = self.code[offset]
306306
op_name = self.op_name(op)
307+
op_type = get_optype(op, self.opc)
307308

308309
oparg = None
309310
pattr = None
@@ -470,7 +471,15 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
470471
if offset not in replace:
471472
new_tokens.append(
472473
Token(
473-
op_name, oparg, pattr, offset, linestart, op, has_arg, self.opc
474+
op_name,
475+
oparg,
476+
pattr,
477+
offset,
478+
linestart,
479+
op,
480+
has_arg,
481+
self.opc,
482+
optype=op_type,
474483
)
475484
)
476485
else:
@@ -484,6 +493,7 @@ def ingest(self, co, classname=None, code_objects={}, show_asm=None):
484493
op,
485494
has_arg,
486495
self.opc,
496+
optype=op_type,
487497
)
488498
)
489499
pass

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)

uncompyle6/semantics/n_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ def n_const_list(self, node: SyntaxTree):
275275
if elem == "ADD_VALUE":
276276
if elem.optype in ("local", "name"):
277277
value = elem.attr
278-
elif elem.optype == "const" and not isinstance(elem.attr, str):
279-
value = elem.attr
278+
elif elem.optype == "const":
279+
value = elem.pattr
280280
else:
281281
value = "%s" % repr(elem.attr)
282282
else:

0 commit comments

Comments
 (0)