Skip to content

Commit 64dcbb0

Browse files
authored
[3.13] gh-133122: Fix for test_type_lookup_mro_reference. (gh-133127)
Change the unit test case to use `getattr()` so that we avoid the bytecode specializer optimizing the access. The specializer will call the `__eq__` method before the unit test expects, causing it to fail. In the 3.14 branch (gh-128164) the test is changed in a different way to avoid the same issue.
1 parent ca46ec8 commit 64dcbb0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/test/test_descr.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5177,10 +5177,15 @@ class Base2(object):
51775177

51785178
with self.assertWarnsRegex(RuntimeWarning, 'X'):
51795179
X = type('X', (Base,), {MyKey(): 5})
5180+
5181+
# Note that the access below uses getattr() rather than normally
5182+
# accessing the attribute. That is done to avoid the bytecode
5183+
# specializer activating on repeated runs of the test.
5184+
51805185
# mykey is read from Base
5181-
self.assertEqual(X.mykey, 'from Base')
5186+
self.assertEqual(getattr(X, 'mykey'), 'from Base')
51825187
# mykey2 is read from Base2 because MyKey.__eq__ has set __bases__
5183-
self.assertEqual(X.mykey2, 'from Base2')
5188+
self.assertEqual(getattr(X, 'mykey2'), 'from Base2')
51845189

51855190

51865191
class PicklingTests(unittest.TestCase):

0 commit comments

Comments
 (0)