gh-126072: do not add None to co_consts if no docstring#126101
gh-126072: do not add None to co_consts if no docstring#126101markshannon merged 26 commits intopython:mainfrom
None to co_consts if no docstring#126101Conversation
|
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 |
JelleZijlstra
left a comment
There was a problem hiding this comment.
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, |
willingc
left a comment
There was a problem hiding this comment.
Looks good. One small edit for the language reference.
markshannon
left a comment
There was a problem hiding this comment.
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 |
willingc
left a comment
There was a problem hiding this comment.
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_DOCSTRINGis set as0x0040, but I found it has been used by theCO_NOFREEininspect.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/