mirror of
https://github.com/python/cpython.git
synced 2025-08-26 19:55:24 +00:00
GH-95150: Use position and exception tables for code hashing and equality (GH-95509)
(cherry picked from commit c7e5bbaee8
)
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
This commit is contained in:
parent
76d83b1dfe
commit
7baca3c05e
5 changed files with 68 additions and 5 deletions
|
@ -428,6 +428,27 @@ class CodeTest(unittest.TestCase):
|
|||
self.assertIsNone(line)
|
||||
self.assertEqual(end_line, new_code.co_firstlineno + 1)
|
||||
|
||||
def test_code_equality(self):
|
||||
def f():
|
||||
try:
|
||||
a()
|
||||
except:
|
||||
b()
|
||||
else:
|
||||
c()
|
||||
finally:
|
||||
d()
|
||||
code_a = f.__code__
|
||||
code_b = code_a.replace(co_linetable=b"")
|
||||
code_c = code_a.replace(co_exceptiontable=b"")
|
||||
code_d = code_b.replace(co_exceptiontable=b"")
|
||||
self.assertNotEqual(code_a, code_b)
|
||||
self.assertNotEqual(code_a, code_c)
|
||||
self.assertNotEqual(code_a, code_d)
|
||||
self.assertNotEqual(code_b, code_c)
|
||||
self.assertNotEqual(code_b, code_d)
|
||||
self.assertNotEqual(code_c, code_d)
|
||||
|
||||
|
||||
def isinterned(s):
|
||||
return s is sys.intern(('_' + s + '_')[1:-1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue