From 399e5673f61cd495b4bd2960a3c0b8dfefaa6945 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 31 Jul 2026 13:16:48 +0200 Subject: [PATCH] gh-151728: Revert "Clear the typing caches at interpreter shutdown (GH-154858)" Unfortunately, this change causes reference leak tests to fail. --- Lib/typing.py | 6 ------ .../Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst | 4 ---- 2 files changed, 10 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst diff --git a/Lib/typing.py b/Lib/typing.py index 809c0ff88607a59..a05d73c29cf95e5 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -19,7 +19,6 @@ """ from abc import abstractmethod, ABCMeta -import atexit import collections from collections import defaultdict import collections.abc @@ -398,11 +397,6 @@ def _clear_caches(): cleanup() -# Release the LRU caches at shutdown, they otherwise redistribute reference -# leaks of one extension to types of unrelated ones. See GH-151728. -atexit.register(_clear_caches) - - def _tp_cache(func=None, /, *, typed=False): """Internal wrapper caching __getitem__ of generic types. diff --git a/Misc/NEWS.d/next/Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst b/Misc/NEWS.d/next/Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst deleted file mode 100644 index 39c63a1aea3193a..000000000000000 --- a/Misc/NEWS.d/next/Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst +++ /dev/null @@ -1,4 +0,0 @@ -Clear the internal :mod:`typing` caches from an exit handler. Previously, an -extension module that leaked a reference to :mod:`typing` would also keep every -subscripted type alive past interpreter shutdown, including types owned by -unrelated extension modules.