10000 gh-98253: Break potential reference cycles in external code worsened by typing.py lru_cache by wjakob · Pull Request #98591 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-98253: Break potential reference cycles in external code worsened by typing.py lru_cache #98591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 30, 2022
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
0