diff options
author | Tian Gao <gaogaotiantian@hotmail.com> | 2023-09-09 01:24:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-09 01:24:49 (GMT) |
commit | 057bc7249073066ed8087b548ee06f0eabfa9e7c (patch) | |
tree | 97d123718225d24a6baf505d946bf027ee5b9ca4 /Lib/test/test_code.py | |
parent | a56c92875699c2ba92ed49e72f6abbf363a5c537 (diff) | |
download | cpython-057bc7249073066ed8087b548ee06f0eabfa9e7c.zip cpython-057bc7249073066ed8087b548ee06f0eabfa9e7c.tar.gz cpython-057bc7249073066ed8087b548ee06f0eabfa9e7c.tar.bz2 |
gh-109052: Use the base opcode when comparing code objects (gh-109107)
Diffstat (limited to 'Lib/test/test_code.py')
-rw-r--r-- | Lib/test/test_code.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 812c068..a961ddb 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -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]) |