gh-123340: Show string value of `IS_OP` oparg in `dis` (#123348)

This commit is contained in:
sobolevn 2024-08-26 21:59:50 +03:00 committed by GitHub
parent 7bd6ebf696
commit 1eed0f968f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 0 deletions

View File

@ -51,6 +51,7 @@ LOAD_SPECIAL = opmap['LOAD_SPECIAL']
LOAD_FAST_LOAD_FAST = opmap['LOAD_FAST_LOAD_FAST']
STORE_FAST_LOAD_FAST = opmap['STORE_FAST_LOAD_FAST']
STORE_FAST_STORE_FAST = opmap['STORE_FAST_STORE_FAST']
IS_OP = opmap['IS_OP']
CACHE = opmap["CACHE"]
@ -629,6 +630,8 @@ class ArgResolver:
argrepr = repr(obj)
elif deop == LOAD_SPECIAL:
argrepr = _special_method_names[arg]
elif deop == IS_OP:
argrepr = 'is not' if argval else 'is'
return argval, argrepr
def get_instructions(x, *, first_line=None, show_caches=None, adaptive=False):

View File

@ -2028,6 +2028,15 @@ class InstructionTests(InstructionTestCase):
dis.dis(f.__code__, file=output, show_caches=True)
self.assertIn("L1:", output.getvalue())
def test_is_op_format(self):
output = io.StringIO()
dis.dis("a is b", file=output, show_caches=True)
self.assertIn("IS_OP 0 (is)", output.getvalue())
output = io.StringIO()
dis.dis("a is not b", file=output, show_caches=True)
self.assertIn("IS_OP 1 (is not)", output.getvalue())
def test_baseopname_and_baseopcode(self):
# Standard instructions
for name, code in dis.opmap.items():

View File

@ -0,0 +1 @@
Show string value of :opcode:`IS_OP` oparg in :mod:`dis` output.