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

mypy --warn-unused-ignores doesn't work #6307

Closed
srittau opened this issue Nov 16, 2021 · 9 comments
Closed

mypy --warn-unused-ignores doesn't work #6307

srittau opened this issue Nov 16, 2021 · 9 comments

Comments

@srittau
Copy link
Collaborator

srittau commented Nov 16, 2021

I'm unsure about the reason, but when I locally run mypy --warn-unused-ignores stdlib/builtins.pyi (or any other file in stdlib or stubs) where I have manually added an unnecessary # type: ignore, I get no warnings. mypy is current in my venv (0.910) and I deleted .mypy_cache to make sure. The same happened when I ran ./tests/mypy_test.py --warn-unused-ignores, which is how I noticed.

Does anyone else have this problem?

@srittau
Copy link
Collaborator Author

srittau commented Nov 16, 2021

And I just double checked: If I create a file foo.pyi in my home directory:

def foo() -> None: ...  # type: ignore

and run mypy ~/foo.pyi --warn-unused-ignores from the typeshed directory, I get a warning. As soon as I move the file to the top-level typeshed directory, I don't get a warning.

@srittau
Copy link
Collaborator Author

srittau commented Nov 16, 2021

And another data point: When I run mypy foo.pyi --warn-unused-ignores in the typeshed dir, then move the file to my home directory, then run mypy ~/foo.pyi --warn-unused-ignores, I don't a warning unless I delete .mypy_cache.

@Akuli
Copy link
Collaborator

Akuli commented Nov 16, 2021

Happens to me too.

(env) akuli@akuli-desktop:~/typeshed$ mypy --warn-unused-ignores stdlib/builtins.pyi 
Success: no issues found in 1 source file
(env) akuli@akuli-desktop:~/typeshed$ rm -rf .mypy_cache/
(env) akuli@akuli-desktop:~/typeshed$ mypy --warn-unused-ignores stdlib/builtins.pyi 
Success: no issues found in 1 source file
(env) akuli@akuli-desktop:~/typeshed$ git diff
diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi
index 6bc58d2a..52fa409d 100644
--- a/stdlib/builtins.pyi
+++ b/stdlib/builtins.pyi
@@ -269,10 +269,10 @@ class float:
     def is_integer(self) -> bool: ...
     @classmethod
     def fromhex(cls, __s: str) -> float: ...
-    @property
-    def real(self) -> float: ...
-    @property
-    def imag(self) -> float: ...
+    @property  # type: ignore
+    def real(self) -> float: ...  # type: ignore
+    @property  # type: ignore  # type: ignore
+    def imag(self) -> float: ...  # type: ignore
     def conjugate(self) -> float: ...
     def __add__(self, __x: float) -> float: ...
     def __sub__(self, __x: float) -> float: ...

@AlexWaygood
Copy link
Member

Same for me, on Windows.

@hauntsaninja
Copy link
Collaborator

You'll want to comment out https://github.com/python/mypy/blob/50db29a527595822fe6f76053a6a54f5c301649a/mypy/errors.py#L465
Note that you'll run into python/mypy#8823, so would need to do some kind of intersection.

Okay, intersecting 3.6 and 3.10 I get:

{'stdlib/_msi.pyi:13',
 'stdlib/_msi.pyi:14',
 'stdlib/_msi.pyi:22',
 'stdlib/_msi.pyi:23',
 'stdlib/_msi.pyi:31',
 'stdlib/_msi.pyi:32',
 'stdlib/_msi.pyi:43',
 'stdlib/_msi.pyi:44',
 'stdlib/_operator.pyi:154',
 'stdlib/builtins.pyi:92',
 'stdlib/builtins.pyi:975',
 'stdlib/importlib/metadata.pyi:77',
 'stdlib/typing.pyi:693',
 'stdlib/typing_extensions.pyi:71',
 'stdlib/weakref.pyi:54'}

From a skim, I think something or the other would complain if you removed them, but please feel free to try,

@JelleZijlstra
Copy link
Member

We figured out the reason for mypy's behavior, so this can be closed.

@yabberyabber
Copy link

@JelleZijlstra Could you provide a little more detail?

Are we using mypy incorrectly? Or is this a bug in mypy that may be fixed in a future release? Is there another issue or PR that might provide more detail?

@JelleZijlstra
Copy link
Member

mypy has specific logic that suppresses this error in typeshed.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 25, 2022

mypy intentionally doesn't respect --warn-unused-ignores in typeshed as linked^^: https://github.com/python/mypy/blob/50db29a527595822fe6f76053a6a54f5c301649a/mypy/errors.py#L465

Enabling --warn-unused-ignores would be problematic, because some type ignores are for other type checkers that use typeshed, or because we have conditional logic on sys.version. The list of potentially removable ignores is in my previous comment, none of them looked actually removable to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants