Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Fix type annotation ofpstats.FunctionProfile.ncalls#96741
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Fix type annotation ofpstats.FunctionProfile.ncalls#96741
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type.
bedevere-bot commentedSep 10, 2022
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
ghost commentedSep 10, 2022 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
bedevere-bot commentedSep 10, 2022
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
bedevere-bot commentedSep 10, 2022
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
AlexWaygood left a comment
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.
LGTM!
This change seems small and straightforward enough not to require an issue, but I am happy to open one if you think it is necessary. I also did not include any tests since this is a type annotation fix without any changes to the runtime behavior.
I agree that this probably doesn't need an issue or NEWS entry, since there's no user-visible change introduced by this PR. (Type checkers use information from typeshed for the stdlib, rather than looking at any annotations in the CPython codebase.) I think the change is still valuable, however, since it's highly confusing forreaders of the code for there to be an incorrect annotation here.
I don't really have an opinion on whether this should be backported or not -- on the one hand, there's no user-visible change here; on the other hand, there's no real risk to it being backported.
AlexWaygood commentedSep 10, 2022
gpshead commentedSep 14, 2022
It's still useful to add a NEWS entry saying "corrected the type annotation on data class blah.blah.thing to be str." |
bedevere-bot commentedSep 14, 2022
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
ruancomelli commentedSep 15, 2022
Hi@gpshead, thanks for the suggestion. I added a NEWS file using |
miss-islington commentedSep 15, 2022
Thanks@ruancomelli for the PR, and@gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
bedevere-bot commentedSep 15, 2022
GH-96835 is a backport of this pull request to the3.11 branch. |
bedevere-bot commentedSep 15, 2022
GH-96836 is a backport of this pull request to the3.10 branch. |
* fix: annotate `pstats.FunctionProfile.ncalls` as `str`This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type.(cherry picked from commit8e9a37d)Co-authored-by: Ruan Comelli <ruancomelli@gmail.com>
* fix: annotate `pstats.FunctionProfile.ncalls` as `str`This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type.(cherry picked from commit8e9a37d)Co-authored-by: Ruan Comelli <ruancomelli@gmail.com>
The annotation in CPython was fixed thanks to@ruancomelli inpython/cpython#96741!
The annotation in CPython was fixed thanks to@ruancomelli inpython/cpython#96741!
This PR aligns the type annotation of
pstats.FunctionProfile.ncallswith its runtimestrtype.The fact that the runtime type of
pstats.FunctionProfile.ncallsisstrcan be verified by (1) inspecting the source code forpstatsand (2) running a small test snippet:in the source code for
pstats, the only place wherencallsis defined seems to becpython/Lib/pstats.py
Line 372 in6281aff
you can also check that
stats.FunctionProfile.ncallsis a string by running the following script:I also have an open PR in
typeshedto fix this issue there:python/typeshed#8712.This change seems small and straightforward enough not to require an issue, but I am happy to open one if you think it is necessary. I also did not include any tests since this is a type annotation fix without any changes to the runtime behavior.