-
-
Notifications
You must be signed in to change notification settings - Fork 31.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
Fix type annotation of pstats.FunctionProfile.ncalls
#96741
Fix type annotation of pstats.FunctionProfile.ncalls
#96741
Conversation
This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type.
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
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 for readers 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.
It's still useful to add a NEWS entry saying "corrected the type annotation on data class blah.blah.thing to be str." |
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Hi @gpshead, thanks for the suggestion. I added a NEWS file using |
Thanks @ruancomelli for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
GH-96835 is a backport of this pull request to the 3.11 branch. |
GH-96836 is a backport of this pull request to the 3.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 commit 8e9a37d) Co-authored-by: Ruan Comelli <[email protected]>
* fix: annotate `pstats.FunctionProfile.ncalls` as `str` This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type. (cherry picked from commit 8e9a37d) Co-authored-by: Ruan Comelli <[email protected]>
The annotation in CPython was fixed thanks to @ruancomelli in python/cpython#96741!
The annotation in CPython was fixed thanks to @ruancomelli in python/cpython#96741!
…) (#96835) This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type. (cherry picked from commit 8e9a37d) Co-authored-by: Ruan Comelli <[email protected]>
…) (#96836) This change aligns the type annotation of `pstats.FunctionProfile.ncalls` with its runtime type. (cherry picked from commit 8e9a37d) Co-authored-by: Ruan Comelli <[email protected]>
This PR aligns the type annotation of
pstats.FunctionProfile.ncalls
with its runtimestr
type.The fact that the runtime type of
pstats.FunctionProfile.ncalls
isstr
can be verified by (1) inspecting the source code forpstats
and (2) running a small test snippet:in the source code for
pstats
, the only place wherencalls
is defined seems to becpython/Lib/pstats.py
Line 372 in 6281aff
you can also check that
stats.FunctionProfile.ncalls
is a string by running the following script:I also have an open PR in
typeshed
to 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.