-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
functools.update_wrapper
and functools.wraps
cannot be used in mypycified files on py312
#16077
Labels
Comments
AlexWaygood
changed the title
Sep 9, 2023
functools.update_wrapper
cannot be used in mypycified files on py312functools.update_wrapper
and functools.wraps
cannot be used in mypycified files on py312
(This bug is affecting |
(@JelleZijlstra is also running into this error locally using macOS) |
@JukkaL do we need to add a |
hauntsaninja
added a commit
to hauntsaninja/mypy
that referenced
this issue
Sep 10, 2023
achimnol
added a commit
to lablup/backend.ai-oven
that referenced
this issue
Oct 9, 2023
hauntsaninja
added a commit
that referenced
this issue
Oct 15, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
Mypycifying a file that uses
functools.update_wrapper
orfunctools.wraps
breaks if you're using Python 3.12.To Reproduce
Ensure you're using Python 3.12
Save this code into a file
repro.py
:Run
mypyc repro.py
Run
python -c "import repro"
Expected Behavior
The mypycified
repro
module should import without errors. This is the behaviour you get if you mypycify the module using Python 3.11.Actual Behavior
Notes on the bug
What is causing the bug?
The bug appears to be due to mypyc not creating
__dict__
attributes for function objects. This appears to be despite this comment in the source code, which looks like it's intended to create__dict__
attributes for functions precisely due to howfunctools.update_wrapper
works:mypy/mypyc/irbuild/callable_class.py
Lines 60 to 65 in 4941983
Why is the bug only occurring on Python 3.12?
The bug with
functools.update_wrapper
only occurs with Python 3.12. The interesting thing is that you can reproduce a similar bug with this snippet, but unlike the first snippet, this will also repro the bug on Python 3.11:Error when running
python -c "import repro"
after mypycifying this snippet:It's unclear to me why
functools.update_wrapper
works on Python 3.11 and breaks on Python 3.12 (snippet 1), when the "inlined" version (snippet 2) breaks on both Python 3.11 and Python 3.12.Did
functools.update_wrapper
change in Python 3.12?There was a minor change to
update_wrapper
in Python 3.12 as part of the PEP-695 implementation: python/cpython#104601. Other than this change, however, the source code forupdate_wrapper
andwraps
has remained unchanged for the last 10 years.Your Environment
The text was updated successfully, but these errors were encountered: