Skip to content

Commit d525c53

Browse files
committed
import _specializations, _specialized_instructions directly from _opcode_metadata rather than via opcode
1 parent 71ffe34 commit d525c53

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

Lib/dis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
_nb_ops,
1616
_intrinsic_1_descs,
1717
_intrinsic_2_descs,
18-
_specializations,
19-
_specialized_instructions,
2018
)
2119

20+
from _opcode_metadata import _specializations, _specialized_instructions
21+
2222
__all__ = ["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
2323
"hasjabs", "hasfree", "haslocal", "hasexc", "hascompare",
2424
"stack_effect", "code_info", "dis", "disassemble", "distb",

Lib/opcode.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
__all__ = ["cmp_op", "opname", "opmap", "HAVE_ARGUMENT", "EXTENDED_ARG"]
99

10-
import sys
11-
# The build uses older versions of Python which do not have _opcode_metadata
12-
if sys.version_info[:2] >= (3, 13):
13-
from _opcode_metadata import _specializations, _specialized_instructions
14-
1510
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
1611

1712

Lib/test/test__opcode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test.support.import_helper import import_module
33
import unittest
44
import opcode
5+
import _opcode_metadata
56

67
_opcode = import_module("_opcode")
78
from _opcode import stack_effect
@@ -105,7 +106,7 @@ def test_specialization_stats(self):
105106
stat_names = ["success", "failure", "hit", "deferred", "miss", "deopt"]
106107
specialized_opcodes = [
107108
op.lower()
108-
for op in opcode._specializations
109+
for op in _opcode_metadata._specializations
109110
if opcode._inline_cache_entries[opcode.opmap[op]]
110111
]
111112
self.assertIn('load_attr', specialized_opcodes)

Lib/test/test_dis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from test.support.bytecode_helper import BytecodeTestCase
1313

1414
import opcode
15+
import _opcode_metadata
1516

1617

1718
def get_tb():
@@ -1939,12 +1940,12 @@ def test_baseopname_and_baseopcode(self):
19391940
self.assertEqual(code, baseopcode)
19401941

19411942
# Specialized instructions
1942-
for name in opcode._specialized_instructions:
1943+
for name in _opcode_metadata._specialized_instructions:
19431944
instruction = Instruction(opname=name, opcode=dis._all_opmap[name], arg=None, argval=None, argrepr='',
19441945
offset=0, start_offset=0, starts_line=1, is_jump_target=False, positions=None)
19451946
baseopname = instruction.baseopname
19461947
baseopcode = instruction.baseopcode
1947-
self.assertIn(name, opcode._specializations[baseopname])
1948+
self.assertIn(name, _opcode_metadata._specializations[baseopname])
19481949
self.assertEqual(opcode.opmap[baseopname], baseopcode)
19491950

19501951
def test_jump_target(self):

Lib/test/test_embed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
354354
code = textwrap.dedent("""\
355355
import dis
356356
import importlib._bootstrap
357-
import opcode
357+
import _opcode_metadata
358358
import test.test_dis
359359
360360
def is_specialized(f):
361361
for instruction in dis.get_instructions(f, adaptive=True):
362362
opname = instruction.opname
363363
if (
364-
opname in opcode._specialized_instructions
364+
opname in _opcode_metadata._specialized_instructions
365365
# Exclude superinstructions:
366366
and "__" not in opname
367367
):

0 commit comments

Comments
 (0)