diff --git a/Lib/dis.py b/Lib/dis.py index f7a31f2f96b99b..db3730122f6b29 100644 --- a/Lib/dis.py +++ b/Lib/dis.py @@ -4,6 +4,8 @@ import types import collections import io +import _opcode +from _opcode import stack_effect from opcode import * from opcode import ( @@ -17,7 +19,9 @@ _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 @@ -25,6 +29,18 @@ _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'] diff --git a/Lib/opcode.py b/Lib/opcode.py index 08dfd2674dca78..c2f8d8c4904054 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -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 @@ -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", "&"),