Skip to content

Commit 25eb25a

Browse files
committed
Record the last __new__ lookup by class name instead of counting
1 parent 25924ec commit 25eb25a

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

Lib/test/picklecommon.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,13 @@ class MyIntWithNew2(MyIntWithNew):
292292

293293
# For test_newobj_metaclass_lookup
294294
class LookupLoggingMeta(type):
295-
new_lookup_count = 0
295+
# Name of the last class whose __new__ was looked up through the
296+
# metaclass.
297+
last_new_lookup = None
296298

297299
def __getattribute__(cls, name):
298300
if name == '__new__':
299-
LookupLoggingMeta.new_lookup_count += 1
301+
LookupLoggingMeta.last_new_lookup = cls.__name__
300302
return super().__getattribute__(name)
301303

302304
class NewInheriting(metaclass=LookupLoggingMeta):

Lib/test/pickletester.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,11 +3608,12 @@ def test_newobj_metaclass_lookup(self):
36083608
for proto in protocols[min_proto:]:
36093609
with self.subTest(cls=cls, proto=proto):
36103610
s = self.dumps(cls(42), proto)
3611-
before = LookupLoggingMeta.new_lookup_count
3611+
LookupLoggingMeta.last_new_lookup = None
36123612
y = self.loads(s)
36133613
self.assertIs(type(y), cls)
36143614
self.assertEqual(y.value, 42)
3615-
self.assertGreater(LookupLoggingMeta.new_lookup_count, before)
3615+
self.assertEqual(LookupLoggingMeta.last_new_lookup,
3616+
cls.__name__)
36163617

36173618
def test_newobj_not_class(self):
36183619
# Issue 24552

0 commit comments

Comments
 (0)