Skip to content

Fix reveal_type to return its argument #2716

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
Jun 18, 2025

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Jun 18, 2025

reveal_type can be used in the middle of an expression, as in func(reveal_type(obj)), so it needs to return its argument at runtime.

By the way, typing.reveal_type was added to the runtime library in Python 3.11, and also as typing_extensions.reveal_type for all Python versions in typing-extensions 4.1.0, so this monkey-patch is not really needed anymore—maybe we should turn it off by default.

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.

Thanks!

@sobolevn sobolevn merged commit 0a6f017 into typeddjango:master Jun 18, 2025
37 checks passed
@sobolevn
Copy link
Member

maybe we should turn it off by default.

We might, but instead I would suggest using builtins.reveal_type = typing_extensions.reveal_type

It is not cool to crash mypy, when you left unimported reveal_type somewhere :(

@andersk andersk deleted the reveal_type branch June 18, 2025 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants