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 an optional error code for unimported reveal_type / reveal_locals #16270

Closed
sobolevn opened this issue Oct 16, 2023 · 0 comments · Fixed by #16271
Closed

Add an optional error code for unimported reveal_type / reveal_locals #16270

sobolevn opened this issue Oct 16, 2023 · 0 comments · Fixed by #16271
Assignees
Labels
feature topic-reveal-type reveal_type() and reveal_locals()

Comments

@sobolevn
Copy link
Member

Some of our users report that reveal_type causes problems in runtime: typeddjango/django-stubs#590

I agree that this is indeed problematic. For example:

x = 1
reveal_type(x)

Mypy checks this code, finds 0 issues, returns 0 as the return code. This script will pass the CI, but will break in runtime. This is not what mypy is expected to do: it is expected to find bugs.

So, I propose adding a new error code:

  • We can name it unimported-reveal
  • It will be turned off by default
  • It will raise errors on all plain reveal_type / reveal_locals usages
  • If you want to keep reveal_type even in production (for some reason), use from typing[_extensions] import reveal_type or type: ignore[unimported-reveal]

Do others have any objections?

@sobolevn sobolevn added feature topic-reveal-type reveal_type() and reveal_locals() labels Oct 16, 2023
@sobolevn sobolevn self-assigned this Oct 16, 2023
sobolevn added a commit that referenced this issue Oct 18, 2023
Note: `reveal_type(1) # type: ignore` is problematic, because it
silences the output. So, I've added some docs to advertise not doing so.

Closes #16270

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature topic-reveal-type reveal_type() and reveal_locals()
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant