Skip to content

Commit

Permalink
[3.12] gh-121084: Fix test_typing random leaks (GH-121360) (#121372)
Browse files Browse the repository at this point in the history
gh-121084: Fix test_typing random leaks (GH-121360)

Clear typing ABC caches when running tests for refleaks (-R option):
call _abc_caches_clear() on typing abstract classes and their
subclasses.
(cherry picked from commit 5f660e8)

Co-authored-by: Victor Stinner <vstinner@python.org>
  • Loading branch information
miss-islington and vstinner committed Jul 4, 2024
1 parent 8d3f44a commit 4bf4cc2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 4bf4cc2

Please sign in to comment.