Skip to content

add support for typing.reveal_type #12117

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

Merged
merged 1 commit into from
Feb 3, 2022
Merged

add support for typing.reveal_type #12117

merged 1 commit into from
Feb 3, 2022

Conversation

JelleZijlstra
Copy link
Member

Description

Add support for typing.reveal_type (python/cpython#30646) and typing_extensions.reveal_type (python/typing#1055).

Test Plan

Added two test cases.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks!

I guess we also need to sync typeshed for this to work properly with 3.11+ in production,right?

@@ -1688,6 +1688,22 @@ main:1: note: Revealed type is "Any"
def reveal_type(x: int) -> None: pass
reveal_type("foo") # E: Argument 1 to "reveal_type" has incompatible type "str"; expected "int"

[case testTypingRevealType]
from typing import reveal_type
from typing import reveal_type as show_me_the_type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: Let's also try rt = reveal_type and rt(1)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That actually doesn't work, probably because at the place in semanal where we recognize reveal_type we can't see through assignments yet. Fixing it would probably be a lot more complicated than this PR, so if we think it's worth fixing, we should do it separately. It doesn't seem too important as no user has asked for it so far.

@JelleZijlstra
Copy link
Member Author

Yes, I'll update typeshed at some point too. Thanks for the review! I'll add some additional tests.

@JelleZijlstra JelleZijlstra merged commit 84b9778 into master Feb 3, 2022
@JelleZijlstra JelleZijlstra deleted the revealtype branch February 3, 2022 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants