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

Please consider having special error codes #3381

Closed
NeilGirdhar opened this issue Apr 25, 2022 · 7 comments
Closed

Please consider having special error codes #3381

NeilGirdhar opened this issue Apr 25, 2022 · 7 comments
Labels
as designed Not a bug, working as intended enhancement request New feature or request

Comments

@NeilGirdhar
Copy link

NeilGirdhar commented Apr 25, 2022

I use both MyPy and Pyright on the same project. In some rare instances, Pyright has a false positive where MyPy does not. I mark these with # type: ignore[pyright].

The problem is that when I call MyPy with warn_unused_ignores = true, I get things like:

cmm/visualization/main_window.py:42: error: Unused "type: ignore" comment
                application.aboutToQuit.connect(self.plot_thread.terminate)  # type: ignore[pyright]

In my ideal world, Pyright would have its own error codes, and MyPy would know to ignore those when warning.

See python/mypy#12671 for the parallel MyPy issue, which is probably more important.

@NeilGirdhar NeilGirdhar added the enhancement request New feature or request label Apr 25, 2022
@erictraut
Copy link
Collaborator

Pyright emits over 600 different error messages, and we're continually adding and tweaking these. Adding a separate error code for each one would be a big maintenance headache, and we don't have any current plans to do this.

Pyright groups each of these error messages under about 60 different named "diagnostic rules". Each diagnostic is reported with its diagnostic rule.

I recently added a mechanism that I think will address your needs. You can now add a # pyright: ignore comment at the end of a line. You can also optionally add the name of one or more diagnostic rules in brackets, such as # pyright: ignore[reportInvalidTypeVarUse] to suppress that error. See this documentation for details. This mechanism also works with the reportUnnecessaryTypeIgnoreComment option, which reports no-longer-needed diagnostic suppression comments.

If you see a legitimate false positive error generated by pyright, please file a bug so we can address it.

@erictraut erictraut added the as designed Not a bug, working as intended label Apr 25, 2022
@NeilGirdhar
Copy link
Author

Awesome! That completely satisfies my needs. I will just do that.

@NeilGirdhar
Copy link
Author

NeilGirdhar commented Apr 25, 2022

@erictraut Is there a way to have pyright warn on unused # pyright: ignore directives?

@erictraut
Copy link
Collaborator

This mechanism also works with the reportUnnecessaryTypeIgnoreComment option, which reports no-longer-needed diagnostic suppression comments.

@NeilGirdhar
Copy link
Author

Oh, but that triggers on all of the type ignores I added for mypy. Is there a way to report only for unnecessary # pyright: ignore comments?

@erictraut
Copy link
Collaborator

No, reportUnnecessaryTypeIgnoreComment applies to # type: ignore and # pyright: ignore.

If you want mypy-specific errors, you'll need to convince the mypy maintainers to implement that. The # type: ignore comment is defined in PEP 484 and isn't specific to any type checker.

@NeilGirdhar
Copy link
Author

I know you're right. You're an idealist like me 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended enhancement request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants