Skip to content

Commit

Permalink
pythongh-121084: Clear typing ABC caches when checking for refleaks
Browse files Browse the repository at this point in the history
Call _abc_caches_clear() on typing abstract classes and their
subclasses when running tests to check for refleaks (-R option).
  • Loading branch information
vstinner committed Jul 4, 2024
1 parent 19d1e43 commit 0f41e17
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,13 @@ def clear_caches():
for f in typing._cleanups:
f()

import inspect
abs_classes = [getattr(typing, attr) for attr in typing.__all__]
abs_classes = filter(inspect.isabstract, abs_classes)
for abc in abs_classes:
for obj in abc.__subclasses__() + [abc]:
obj._abc_caches_clear()

try:
fractions = sys.modules['fractions']
except KeyError:
Expand Down

0 comments on commit 0f41e17

Please sign in to comment.