-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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
singledispatch.register
fails for lru_cache
decorated functions
#132064
Comments
See here (PR to my own package) for implemented workaround, tested with tox for py39~py314 on ubuntu, macOS and windows (-latest). |
Also, i'd say there are at least two things wrong here:
|
@rhettinger Was |
for reference, it worked as far back as i've tested, aka down to 3.9. i do realise it might not have been intended to work though, and so this is not necessarily a feature. |
Oh so you mean that it's a 3.14+ issue? |
yes! sorry, reading back i was not clear about that 😅 (added an |
As it uses |
|
This is indeed a consequence of the implementation of PEP 649/PEP 749, specifically this section: https://peps.python.org/pep-0749/#wrappers-that-provide-annotations . It is fixable in |
@JelleZijlstra, The lru_cache has a pure python implementation as well. The wrapping of both the pure python version and the C version is done in Can this be fixed for the general case by expanding diff --git a/Lib/functools.py b/Lib/functools.py
index 714070c6ac9..489b3e1071c 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -30,7 +30,7 @@
# wrapper functions that can handle naive introspection
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__doc__',
- '__annotate__', '__type_params__')
+ '__annotate__', '__annotations__', '__type_params__')
WRAPPER_UPDATES = ('__dict__',)
def update_wrapper(wrapper,
wrapped, Looking at the |
No, adding |
The Python implementation of lru_cache already works on 3.14, so it doesn't need any changes to fix this issue. (To test, take the OP's script, comment out the lines in functools.py that import the C implementation, and run the script.) |
Another possibility is for Presumably, |
I found a better fix for the original issue reported here: #132195. This makes annotationlib use the With that fix, it's still the case though that
This could impact users who (against recommendations) access |
Bug report
Function decorated with both
@singledispatch.register
and@lru_chache
fails with a cryptic error message.EDIT: In python 3.14a6. It works in python 3.9~3.13.
Bug description:
python ./singledispatch_mwe.py
, butpython ./singledispatch_mwe.py --broken-in-py314
produces the following error:In python 3.9~3.13 both of the above work.
CPython versions tested on:
3.9~3.14
Operating systems tested on:
macOS
Linked PRs
The text was updated successfully, but these errors were encountered: