Skip to content

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

Description

@srittau

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?

Activity

  1. srittau commented on Nov 16, 2021

    @srittau
    CollaboratorAuthor

    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.

  2. srittau commented on Nov 16, 2021

    @srittau
    CollaboratorAuthor

    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.

  3. Akuli commented on Nov 16, 2021

    @Akuli
    Collaborator

    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: ...
    
  4. AlexWaygood commented on Nov 16, 2021

    @AlexWaygood
    Member

    Same for me, on Windows.

  5. hauntsaninja commented on Dec 2, 2021

    @hauntsaninja
    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,

  6. JelleZijlstra commented on Feb 12, 2022

    @JelleZijlstra
    Member

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

  7. yabberyabber commented on Feb 25, 2022

    @yabberyabber

    @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?

  8. JelleZijlstra commented on Feb 25, 2022

    @JelleZijlstra
    Member

    mypy has specific logic that suppresses this error in typeshed.

  9. hauntsaninja commented on Feb 25, 2022

    @hauntsaninja
    Collaborator

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions