| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c6e8b8 commit ef3f8c9
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | import collections | |
| 4 | 4 | import collections.abc | |
| 5 | 5 | import copy | |
| 6 | + import gc | ||
| 6 | 7 | from itertools import permutations | |
| 7 | 8 | import pickle | |
| 8 | 9 | from random import choice | |
@@ -3246,6 +3247,33 @@ def dispatch(self, x): | |||
| 3246 | 3247 | assert id(t1) == t1.dispatch(2) | |
| 3247 | 3248 | assert id(t2) == t2.dispatch(2) # gh-127750 | |
| 3248 | 3249 | ||
| 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 | + | ||
| 3249 | 3277 | ||
| 3250 | 3278 | class CachedCostItem: | |
| 3251 | 3279 | _cost = 1 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments