Skip to content
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

add support for typing.reveal_type #12117

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

@JelleZijlstra JelleZijlstra commented Feb 3, 2022

Description

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

Test Plan

Added two test cases.

@JelleZijlstra JelleZijlstra requested a review from sobolevn Feb 3, 2022
Copy link
Member

@sobolevn sobolevn left a comment

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

@sobolevn sobolevn Feb 3, 2022

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

@JelleZijlstra JelleZijlstra Feb 3, 2022

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

@JelleZijlstra JelleZijlstra commented Feb 3, 2022

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
15 checks passed
@JelleZijlstra JelleZijlstra deleted the revealtype branch Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants