gh-121084: Fix test_typing random leaks (#121360)

Clear typing ABC caches when running tests for refleaks (-R option):
call _abc_caches_clear() on typing abstract classes and their
subclasses.
This commit is contained in:
Victor Stinner 2024-07-04 19:38:30 +02:00 committed by GitHub
parent f5c8d67de6
commit 5f660e8e2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -264,6 +264,12 @@ def clear_caches():
for f in typing._cleanups:
f()
import inspect
abs_classes = filter(inspect.isabstract, typing.__dict__.values())
for abc in abs_classes:
for obj in abc.__subclasses__() + [abc]:
obj._abc_caches_clear()
try:
fractions = sys.modules['fractions']
except KeyError:

View File

@ -0,0 +1,3 @@
Fix test_typing random leaks. Clear typing ABC caches when running tests for
refleaks (``-R`` option): call ``_abc_caches_clear()`` on typing abstract
classes and their subclasses. Patch by Victor Stinner.