Repository navigation
mypy --warn-unused-ignores doesn't work #6307
Description
Activity
And I just double checked: If I create a file
foo.pyiin my home directory:def foo() -> None: ... # type: ignore
and run
mypy ~/foo.pyi --warn-unused-ignoresfrom 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.And another data point: When I run
mypy foo.pyi --warn-unused-ignoresin the typeshed dir, then move the file to my home directory, then runmypy ~/foo.pyi --warn-unused-ignores, I don't a warning unless I delete.mypy_cache.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: ...Same for me, on Windows.
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,
We figured out the reason for mypy's behavior, so this can be closed.
@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?
mypy has specific logic that suppresses this error in typeshed.
mypy intentionally doesn't respect
--warn-unused-ignoresin typeshed as linked^^: https://github.com/python/mypy/blob/50db29a527595822fe6f76053a6a54f5c301649a/mypy/errors.py#L465Enabling
--warn-unused-ignoreswould 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.
I'm unsure about the reason, but when I locally run
mypy --warn-unused-ignores stdlib/builtins.pyi(or any other file instdliborstubs) 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_cacheto 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?