mirror of
https://github.com/python/cpython.git
synced 2025-08-25 03:04:55 +00:00
gh-109052: Use the base opcode when comparing code objects (gh-109107)
This commit is contained in:
parent
a56c928756
commit
057bc72490
3 changed files with 24 additions and 6 deletions
|
@ -505,6 +505,25 @@ class CodeTest(unittest.TestCase):
|
|||
self.assertNotEqual(c, c1)
|
||||
self.assertNotEqual(hash(c), hash(c1))
|
||||
|
||||
@cpython_only
|
||||
def test_code_equal_with_instrumentation(self):
|
||||
""" GH-109052
|
||||
|
||||
Make sure the instrumentation doesn't affect the code equality
|
||||
The validity of this test relies on the fact that "x is x" and
|
||||
"x in x" have only one different instruction and the instructions
|
||||
have the same argument.
|
||||
|
||||
"""
|
||||
code1 = compile("x is x", "example.py", "eval")
|
||||
code2 = compile("x in x", "example.py", "eval")
|
||||
sys._getframe().f_trace_opcodes = True
|
||||
sys.settrace(lambda *args: None)
|
||||
exec(code1, {'x': []})
|
||||
exec(code2, {'x': []})
|
||||
self.assertNotEqual(code1, code2)
|
||||
sys.settrace(None)
|
||||
|
||||
|
||||
def isinterned(s):
|
||||
return s is sys.intern(('_' + s + '_')[1:-1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue