From 1a30e79d949de4aaf43e45d44d6cc2346016934f Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 4 Jul 2024 15:07:49 +0200 Subject: [PATCH 1/2] gh-121084: 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. --- Lib/test/libregrtest/utils.py | 7 +++++++ .../Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 0197e50125d96e..122708a44c7a48 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -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: 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 index 00000000000000..b91ea8acfadbf1 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2024-07-04-15-10-29.gh-issue-121084.qxcd5d.rst @@ -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. From f4e2caeaf95735b754b4ada5bdccf9cf2e40c82d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Thu, 4 Jul 2024 15:33:08 +0200 Subject: [PATCH 2/2] Use typing.__dict__ instead of typing.__all__ --- Lib/test/libregrtest/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index 122708a44c7a48..2a3449016fe951 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -265,8 +265,7 @@ def clear_caches(): f() import inspect - abs_classes = [getattr(typing, attr) for attr in typing.__all__] - abs_classes = filter(inspect.isabstract, abs_classes) + abs_classes = filter(inspect.isabstract, typing.__dict__.values()) for abc in abs_classes: for obj in abc.__subclasses__() + [abc]: obj._abc_caches_clear() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy