File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -292,11 +292,13 @@ class MyIntWithNew2(MyIntWithNew):
292292
293293# For test_newobj_metaclass_lookup
294294class 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
302304class NewInheriting (metaclass = LookupLoggingMeta ):
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments