Skip to content

Commit

Permalink
import _opcode directly into dis, rather than via opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel committed Jul 18, 2023
1 parent 75795db commit 1a0a2b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
18 changes: 17 additions & 1 deletion Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import types
import collections
import io
import _opcode
from _opcode import stack_effect

from opcode import *
from opcode import (
Expand All @@ -17,14 +19,28 @@
_specialized_instructions,
)

__all__ = ["code_info", "dis", "disassemble", "distb", "disco",
__all__ = ["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
"hasjabs", "hasfree", "haslocal", "hasexc", "hascompare",
"code_info", "dis", "disassemble", "distb", "disco",
"findlinestarts", "findlabels", "show_code",
"get_instructions", "Instruction", "Bytecode"] + _opcodes_all
del _opcodes_all

_have_code = (types.MethodType, types.FunctionType, types.CodeType,
classmethod, staticmethod, type)

# These lists are documented as part of the dis module's API
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
hasjrel = hasjump # for backward compatibility
hasjabs = []
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]
hascompare = [opmap["COMPARE_OP"]]

CONVERT_VALUE = opmap['CONVERT_VALUE']

SET_FUNCTION_ATTRIBUTE = opmap['SET_FUNCTION_ATTRIBUTE']
Expand Down
25 changes: 1 addition & 24 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
"""


# Note that __all__ is further extended below
__all__ = ["cmp_op", "opname", "opmap", "stack_effect", "hascompare",
"HAVE_ARGUMENT", "EXTENDED_ARG"]

import _opcode
from _opcode import stack_effect
__all__ = ["cmp_op", "opname", "opmap", "HAVE_ARGUMENT", "EXTENDED_ARG"]

import sys
# The build uses older versions of Python which do not have _opcode_metadata
Expand Down Expand Up @@ -241,24 +236,6 @@ def pseudo_op(name, op, real_ops):
for op, i in opmap.items():
opname[i] = op

# The build uses older versions of Python which do not have _opcode.has_* functions
if sys.version_info[:2] >= (3, 13):
# These lists are documented as part of the dis module's API
hasarg = [op for op in opmap.values() if _opcode.has_arg(op)]
hasconst = [op for op in opmap.values() if _opcode.has_const(op)]
hasname = [op for op in opmap.values() if _opcode.has_name(op)]
hasjump = [op for op in opmap.values() if _opcode.has_jump(op)]
hasjrel = hasjump # for backward compatibility
hasjabs = []
hasfree = [op for op in opmap.values() if _opcode.has_free(op)]
haslocal = [op for op in opmap.values() if _opcode.has_local(op)]
hasexc = [op for op in opmap.values() if _opcode.has_exc(op)]

__all__.extend(["hasarg", "hasconst", "hasname", "hasjump", "hasjrel",
"hasjabs", "hasfree", "haslocal", "hasexc"])

hascompare = [opmap["COMPARE_OP"]]

_nb_ops = [
("NB_ADD", "+"),
("NB_AND", "&"),
Expand Down

0 comments on commit 1a0a2b2

Please sign in to comment.