Skip to content

Commit 05c9275

Browse files
authored
Reject invalid opcode names in assertInBytecode (pythonGH-97548)
1 parent c8c0afc commit 05c9275

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

Lib/test/support/bytecode_helper.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_disassembly_as_string(self, co):
1717

1818
def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
1919
"""Returns instr if opname is found, otherwise throws AssertionError"""
20+
self.assertIn(opname, dis.opmap)
2021
for instr in dis.get_instructions(x):
2122
if instr.opname == opname:
2223
if argval is _UNSPECIFIED or instr.argval == argval:
@@ -31,6 +32,7 @@ def assertInBytecode(self, x, opname, argval=_UNSPECIFIED):
3132

3233
def assertNotInBytecode(self, x, opname, argval=_UNSPECIFIED):
3334
"""Throws AssertionError if opname is found"""
35+
self.assertIn(opname, dis.opmap)
3436
for instr in dis.get_instructions(x):
3537
if instr.opname == opname:
3638
disassembly = self.get_disassembly_as_string(x)

0 commit comments

Comments
 (0)