fix: annotate pstats.FunctionProfile.ncalls as str#8712
fix: annotate pstats.FunctionProfile.ncalls as str#8712AlexWaygood merged 3 commits intopython:masterfrom
pstats.FunctionProfile.ncalls as str#8712Conversation
Correctly annotate `pstats.FunctionProfile.ncalls` as `str` instead of `int`.
This comment has been minimized.
This comment has been minimized.
AlexWaygood
left a comment
There was a problem hiding this comment.
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 <Alex.Waygood@Gmail.com>
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. 🤖🎉 |
Correctly annotate
pstats.FunctionProfile.ncallsasstrinstead 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: