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-ignore inconsistent with removed branches #9652

Closed
dvarrazzo opened this issue Oct 27, 2020 · 1 comment
Closed

--warn-unused-ignore inconsistent with removed branches #9652

dvarrazzo opened this issue Oct 27, 2020 · 1 comment
Labels
bug mypy got something wrong

Comments

@dvarrazzo
Copy link

Bug Report

I seems to understand that mypy can detect unused branched (ones checked against sys.version_info) and avoid checking them. However --warn-unused-ignore doesn't apply the same filtering.

As a consequence, an # ignore in a branch that goes unchecked is reported as unused, instead of being ignored. So you can have a statement that is reported as error running mypy with a certain Python version, but, if ignored, the same line will be reported as unneeded with a different Python version.

To Reproduce

# test.py
import sys

def f(a: str) -> int:
    return len(a)

f("hello")
if sys.version_info < (3, 7):
    f(b"world")

Running mypy --warn-unused-ignores test.py with Python 3.6, it will report an arg-type error on the last line, whereas a Python 3.8 test run will be clean.

If a type: ignore[arg-type] comment is added to the last line, the Python 3.6 run will be clean, but Python 3.8 will fail with "unused 'type: ignore' comment".

The expectation is that the type: ignore would be ignored by Python 3.8, if such branch is not checked.

Your Environment

Tested with mypy 0.782, 0.790

@dvarrazzo dvarrazzo added the bug mypy got something wrong label Oct 27, 2020
dvarrazzo added a commit to psycopg/psycopg that referenced this issue Oct 27, 2020
Aligning Travis with my current dev environment to avoid cases where
it's not possible to type-check consistently with different Python
versions.

See python/mypy#9652
@hauntsaninja
Copy link
Collaborator

I think this is a duplicate of #8823 , you can use cast as a workaround

dvarrazzo added a commit to psycopg/psycopg that referenced this issue Oct 28, 2020
Aligning Travis with my current dev environment to avoid cases where
it's not possible to type-check consistently with different Python
versions.

See python/mypy#9652
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants