]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-151728: Clear the typing caches at interpreter shutdown (GH-155002)
authorWenzel Jakob <wenzel.jakob@epfl.ch>
Mon, 3 Aug 2026 15:21:20 +0000 (17:21 +0200)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2026 15:21:20 +0000 (17:21 +0200)
commitc10c7e90befd8ba696c1f96323bf5602d4b6594b
tree880cf5f157a4e4eff7868ae4ce6ad3230fad3e8b
parenta4095ee272f5e5082281a94a0856dde3c2f323f9
gh-151728: Clear the typing caches at interpreter shutdown (GH-155002)

Re-apply GH-154858, which was reverted in GH-154992 because it broke the
reference leak buildbots.

``atexit.register(_clear_caches)`` runs on every import of ``typing``, and the
registered handler reaches the module dict through ``_clear_caches.__globals__``.
Any throwaway copy of ``typing`` therefore stays alive until interpreter
shutdown. Two tests create such a copy on each iteration:

- ``InternalsTests.test_collect_parameters`` imports a fresh ``typing``.
- ``CollectionsAbcTests.test_bytestring`` drops ``typing`` from ``sys.modules``
  and re-imports it.

Both now unregister the exit handler of the copy they created.
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2026-07-29-11-05-00.gh-issue-151728.Kq3vTn.rst [new file with mode: 0644]