Fix type annotation of pstats.FunctionProfile.ncalls#96741
Fix type annotation of pstats.FunctionProfile.ncalls#96741gpshead merged 4 commits intopython:mainfrom
pstats.FunctionProfile.ncalls#96741Conversation
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. |
AlexWaygood
left a comment
There was a problem hiding this comment.
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 <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 commit 8e9a37d) Co-authored-by: Ruan Comelli <ruancomelli@gmail.com>
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!
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 in 6281aff
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.