Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added a comment clarifying the indirection
  • Loading branch information
wjakob committed Nov 25, 2022
commit 411fd55cb86c1cf4befe634e7363dea9599e54ac
5 changes: 5 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ def _tp_cache(func=None, /, *, typed=False):
original function for non-hashable arguments.
"""
def decorator(func):
# The callback 'inner' references the newly created lru_cache
# indirectly by performing a lookup in the global '_caches' dictionary.
# This breaks a reference that can be problematic when combined with
# C API extensions that leak references to types. See GH-98253.

cache = functools.lru_cache(typed=typed)(func)
_caches[func] = cache
_cleanups.append(cache.cache_clear)
Expand Down