]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121084: Fix test_typing random leaks (#121360)
authorVictor Stinner <vstinner@python.org>
Thu, 4 Jul 2024 17:38:30 +0000 (19:38 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Jul 2024 17:38:30 +0000 (19:38 +0200)
Clear typing ABC caches when running tests for refleaks (-R option):
call _abc_caches_clear() on typing abstract classes and their
subclasses.

Lib/test/libregrtest/utils.py
Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst [new file with mode: 0644]

index 0197e50125d96e07e2eae27e2dfffee27a174eb4..2a3449016fe9511aa009da85eafb1e74186654a1 100644 (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:
diff --git a/Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst b/Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst
new file mode 100644 (file)
index 0000000..b91ea8a
--- /dev/null
@@ -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.