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

--warn-unused-ignores in non-checked branches #5940

Closed
srittau opened this issue Nov 23, 2018 · 3 comments
Closed

--warn-unused-ignores in non-checked branches #5940

srittau opened this issue Nov 23, 2018 · 3 comments
Labels
bug mypy got something wrong priority-1-normal topic-type-ignore # type: ignore comments topic-usability

Comments

@srittau
Copy link
Contributor

srittau commented Nov 23, 2018

Consider the following mixed Python 2 and 3 stub:

import sys

if sys.version_info < (3,):
    class X:
        def foo(self) -> int: ...
    class Y(X):
        def foo(self) -> str: ...  # type: ignore

Using mypy 0.641 and Python 3.6.7 when running this with mypy --warn-unused-ignores mypy wll complain:

foo.pyi:7: note: unused 'type: ignore' comment

As expected it will not complain when running in --py2 mode. I believe mypy should not complain about ignores in branches that are not checked.

See also #2961, which is more generic.

@posita
Copy link
Contributor

posita commented Nov 14, 2021

This isn't limited to 2 vs. 3. There are interface complications among versions of 3. This is a contrived example, but it gets the point across:

from abc import abstractmethod
try:
    from typing import Protocol, runtime_checkable
except ImportError:
    from typing_extensions import Protocol, runtime_checkable

@runtime_checkable
class _SupportsFloorCeil(Protocol):
    @abstractmethod
    def __floor__(self) -> int:
        pass
    @abstractmethod
    def __ceil__(self) -> int:
        pass

import sys
val: _SupportsFloorCeil
_default: float = 1.6180339887
if sys.version_info < (3, 9):
    val = _default  # type: ignore [assignment]  # float doesn't have __floor__ or __ceil__ prior to 3.9
else:
    val = _default

@NeilGirdhar
Copy link
Contributor

NeilGirdhar commented Dec 7, 2021

I just ran into this here.

@ilevkivskyi
Copy link
Member

This is a duplicate of #8823 (or rather vice versa, but that issue has more discussion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal topic-type-ignore # type: ignore comments topic-usability
Projects
None yet
Development

No branches or pull requests

5 participants