-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-126072: do not add None
to co_consts
if no docstring
#126101
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some tests, probably to test_code.py
.
You'll also probably need to change the __doc__
descriptor on function objects so it continues to work correctly.
Maybe the optimization pass should be updated as the hypothesis may not hold: Lines 2117 to 2119 in 9b14083
The generated bytecodes for the same function are different before and after this PR. |
FYI, we are in the process of removing small ints from the Can you change the ints in your tests to strings. Doing so will also help test that non-docstring strings do not get interpreted as docstrings. |
There are a few improvements we can make to the bytecode compiler once this PR is done. |
Yeah, what I concern is whether the constant removal optimization will lead to a unexpected results when the first element in |
Currently, as the const removal optimization unconditionally keeps the first element in consts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. One small edit for the language reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this.
This was one of those little things that's been bothering me for a while.
Glad to see it fixed
Update doc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment on inspect.rst.
The UI shows 2 jobs still in progress. But they have completed successfully 🤷♂️ |
Thanks for your review, it's my first PR merged into CPython! And I'm also interested in the following related optimizations. |
Congratulations! in your next PR, add your name to |
Hi @markshannon this is my attempt to implement #126072. Initially the value of
CO_HAS_DOCSTRING
is set as0x0040
, but I found it has been used by theCO_NOFREE
ininspect
.cpython/Lib/inspect.py
Lines 409 to 411 in 85799f1
And I've tested it with the following code:See the test cases in changed test filesI've also updated the related documentation, but maybe there is something I missed. Please help me improve this PR, thank you!
📚 Documentation preview 📚: https://cpython-previews--126101.org.readthedocs.build/