gh-151728: Partially revert "Clear the typing caches at interpreter shutdown (GH-154858)" (GH-154992)

encukou <[email protected]> Fri, 31 Jul 2026 10:01:08 -0400 (EDT)
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/6a139d6e5481d2b5124b84cef9885674256c9d54
commit: 6a139d6e5481d2b5124b84cef9885674256c9d54
branch: main
author: Petr Viktorin <[email protected]>
committer: encukou <[email protected]>
date: 2026-07-31T16:00:12+02:00
summary:

gh-151728: Partially revert "Clear the typing caches at interpreter shutdown (GH-154858)" (GH-154992)

Unfortunately, this change causes reference leak tests to fail.

This only reverts the `atexit` registration: it leaves the `_clear_caches` function, to simplify the regrtest utils code a bit.

files:
D Misc/NEWS.d/next/Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst
M Lib/typing.py

diff --git a/Lib/typing.py b/Lib/typing.py
index 809c0ff88607a5..a05d73c29cf95e 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 39c63a1aea3193..00000000000000
--- 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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]