-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Consistency of reveal_type results with other type checkers #113255
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
Comments
Without type hints: |
Thanks for the report and the careful analysis! But I don't think that full consistency between what CPython shows at runtime for It should be a goal for the statically-known types and the runtime types to be compatible, but this is a very different (and much weaker) goal than identical output from In general, cases where type checkers report types that are not even compatible with the runtime types are bugs in type checkers, not bugs in CPython, and should be reported to the relevant type checker. (Unless of course it's a bug in CPython for another reason, such as violating CPython's own documented intended behavior; but mismatch with a static type checker is not in itself an indication of a bug in CPython.) So I don't believe there is anything actionable for CPython in this report, and I think it should be closed. Will mark it |
I agree with everything @carljm says above. The only thing I can think of that might be actionable here would be to improve the docs around this function: perhaps it could be articulated more clearly that it's not necessarily a bug for the runtime output of this function to differ from the output a type checker emits on encountering this function https://docs.python.org/3/library/typing.html#typing.reveal_type |
Thanks for the comment @carljm! It's very clear and helpful, my confusion is fully resolved. As @AlexWaygood suggested, I used my personal account @note35 to send a PR to improve the doc based on your comment. PTaL! |
Co-authored-by: AlexWaygood <[email protected]>
(cherry picked from commit 11ee912) Co-authored-by: Kir <[email protected]> Co-authored-by: AlexWaygood <[email protected]>
…113323) gh-113255: Clarify docs for `typing.reveal_type` (GH-113286) (cherry picked from commit 11ee912) Co-authored-by: Kir <[email protected]> Co-authored-by: AlexWaygood <[email protected]>
…#113286) (cherry-picked from commit 11ee912) Co-authored-by: AlexWaygood <[email protected]>
…13326) (cherry-picked from commit 11ee912) Co-authored-by: Kir <[email protected]>
Thanks for the PR, @gkirchou! |
Co-authored-by: AlexWaygood <[email protected]>
Co-authored-by: AlexWaygood <[email protected]>
Co-authored-by: AlexWaygood <[email protected]>
Co-authored-by: AlexWaygood <[email protected]>
Bug report
Bug description:
Not sure if this bug is reported before.
FWIK, CPython's
reveal_type
was introduced based on the motivation of the same features in type checkers. But I found out the behavior is inconsistent, at least between CPython, mypy, and pytype based on the cases in Python 3 Types in the Wild: A Tale of Two Type Systems.Case 1:
Case 2
Case 3
For code without type annotations, the current behavior is closer to pytype. Case 2 is unclear, because CPython's
reveal_type
doesn't show the types for the elements.And even if I add type to the code to address mypy errors, the result is still inconsistent:
Case 1:
Case 2
Case 3
I don't know what's the best behavior, while
reveal_type
in CPython may not be fully aligned with any type checker's type systems. Based on the motivation, will it make sense to align the behavior with at least mypy'sreveal_type
?CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux, macOS
Linked PRs
typing.reveal_type
#113286typing.reveal_type
(GH-113286) #113323typing.reveal_type
(#113286) #113326The text was updated successfully, but these errors were encountered: