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

There is no way to ignore valid-type error for valid type alias type statements #16607

Closed
bmitc opened this issue Dec 4, 2023 · 1 comment · Fixed by #16608
Closed

There is no way to ignore valid-type error for valid type alias type statements #16607

bmitc opened this issue Dec 4, 2023 · 1 comment · Fixed by #16608
Labels
bug mypy got something wrong

Comments

@bmitc
Copy link

bmitc commented Dec 4, 2023

Bug Report

Python 3.12 added support for the type statement as described in PEP 695. As discussed in #15238, Mypy does not yet support PEP 695. Unfortunately, it seems that Mypy also does not support ignoring error codes for lines using type.

To Reproduce

After reading the documentation at https://mypy.readthedocs.io/en/stable/error_codes.html#error-codes:

In mypy.ini:

[mypy]
disable_error_code = valid-type

In a Python source file:

type Number = int | float # type: ignore

type AnotherNumber = int | float # type: ignore[valid-type]

type YetAnotherNumber = int | float # mypy: disable-error-code="valid-type"

On the command line:

mypy --disable-error-code='unused-ignore' ...

Expected Behavior

All five of these examples should tell Mypy ignore the valid-type error code.

Actual Behavior

The error code is not ignored. In every case, the following error is still generated:

error: PEP 695 type aliases are not yet supported  [valid-type]

In a few of the cases, an error like

error: Unused "type: ignore" comment  [unused-ignore]

is generated.

Your Environment

  • Mypy version used: 1.7.1
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (and other config files): see above
  • Python version used: 3.12
@bmitc bmitc added the bug mypy got something wrong label Dec 4, 2023
@bmitc bmitc mentioned this issue Dec 4, 2023
10 tasks
@erictraut
Copy link

I don't know if there's much value in suppressing this error in mypy. All subsequent type evaluation based on that type alias will generate errors as well. If you're a mypy user, it's probably best to simply avoid PEP 695 syntax until this support is added.

If you want to explore the new syntax while you're waiting for this support to appear in mypy, you can try the pyright playground.

hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Dec 4, 2023
This is basically a pre-existing bug and affects other errors that
ASTConverter might raise, like merging overloads.

It could vaguely be nice to move all the set_file_ignored_lines into
fastparse, instead of BuildManager.parse_file. Could also clean up the
ignore_errors logic a little bit more.

Fixes python#16607
JukkaL pushed a commit that referenced this issue Dec 7, 2023
This is basically a pre-existing bug and affects other errors that
ASTConverter might raise, like merging overloads.

It could vaguely be nice to move all the set_file_ignored_lines into
fastparse, instead of BuildManager.parse_file. Could also clean up the
ignore_errors logic a little bit more.

Fixes #16607
wesleywright pushed a commit that referenced this issue Dec 7, 2023
This is basically a pre-existing bug and affects other errors that
ASTConverter might raise, like merging overloads.

It could vaguely be nice to move all the set_file_ignored_lines into
fastparse, instead of BuildManager.parse_file. Could also clean up the
ignore_errors logic a little bit more.

Fixes #16607
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants