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

Spurious "undefined name" with "type: ignore" comment for mypy #489

Closed
gward opened this issue Nov 13, 2019 · 1 comment
Closed

Spurious "undefined name" with "type: ignore" comment for mypy #489

gward opened this issue Nov 13, 2019 · 1 comment

Comments

@gward
Copy link

gward commented Nov 13, 2019

mypy has the ability to selectively ignore type errors with special syntax in a type annotation comment. These comments confuse pyflakes and cause it to emit spurious "undefined name" errors.

Sample code using this mypy feature:

def foo(a: str):
    if a == 37:
        return ""
    return a + ""

foo(37)                         # type: ignore[arg-type]

(See https://mypy.readthedocs.io/en/latest/error_codes.html#silencing-errors-based-on-error-codes for more detail.)

pyflakes reports undefined names in that type annotation comment:

$ pyflakes pyflakes-test.py
pyflakes-test.py:6: undefined name 'ignore'
pyflakes-test.py:6: undefined name 'arg'

If I change the type annotation comment to

foo(37)                         # type: ignore

then pyflakes is happy. But I'm not happy, because that will prevent mypy from finding other errors in this line.

@asottile
Copy link
Member

#455 #475 (duplicate) please try against master

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

2 participants