-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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: annotate pstats.FunctionProfile.ncalls
as str
#8712
fix: annotate pstats.FunctionProfile.ncalls
as str
#8712
Conversation
Correctly annotate `pstats.FunctionProfile.ncalls` as `str` instead of `int`.
This comment has been minimized.
This comment has been minimized.
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.
Really interesting. I verified this both by looking at the code in CPython and by trying out your test script -- this seems to be correct.
I'm guessing what happened here is we just copied over the annotation from the CPython source, which appears to be completely incorrect. (Or maybe it's actually correct, and there's meant to be a call to int()
somewhere, but that never happens?)
Either way, this is quite strange, so let's add a comment. And you could consider opening a CPython issue/PR about it :)
Since this change introduces a difference between typeshed and CPython, add a comment pointing that out and linking to this PR. Co-authored-by: Alex Waygood <[email protected]>
This comment has been minimized.
This comment has been minimized.
Thank you for your review @AlexWaygood! Also thanks for your suggestion, I opened a PR to fix this in CPython as well: python/cpython#96741.
Just to answer your last comment, it is intentional that |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
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 @ruancomelli!
Correctly annotate
pstats.FunctionProfile.ncalls
asstr
instead ofint
, aligning the static type with the runtime one.The reason why it is a string at runtime is indicated in the profiling instant user's manual:
This behavior can be tested at runtime with the following script: