File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 33import collections
44import collections .abc
55import copy
6+ import gc
67from itertools import permutations
78import pickle
89from random import choice
@@ -3246,6 +3247,33 @@ def dispatch(self, x):
32463247 assert id (t1 ) == t1 .dispatch (2 )
32473248 assert id (t2 ) == t2 .dispatch (2 ) # gh-127750
32483249
3250+ def test_singledispatchmethod_object_references (self ):
3251+ class ReferenceTest :
3252+ instance_counter = 0
3253+
3254+ def __init__ (self ):
3255+ ReferenceTest .instance_counter = ReferenceTest .instance_counter + 1
3256+
3257+ def __del__ (self ):
3258+ ReferenceTest .instance_counter = ReferenceTest .instance_counter - 1
3259+
3260+ @functools .singledispatchmethod
3261+ def go (self , item ):
3262+ pass
3263+
3264+ assert ReferenceTest .instance_counter == 0
3265+ t = ReferenceTest ()
3266+ assert ReferenceTest .instance_counter == 1
3267+ x = []
3268+ for ii in range (1000 ):
3269+ t = ReferenceTest ()
3270+ t .go (ii )
3271+ x .append (t )
3272+ del t
3273+ del x
3274+ gc .collect ()
3275+ assert ReferenceTest .instance_counter == 0
3276+
32493277
32503278class CachedCostItem :
32513279 _cost = 1
You can’t perform that action at this time.
0 commit comments