8000 "# type: ignore[no-redef]" causing "Module 'x' has no attribute 'y'" errors. · Issue #8016 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

"# type: ignore[no-redef]" causing "Module 'x' has no attribute 'y'" errors. #8016

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

Closed
jonathanslenders opened this issue Nov 26, 2019 · 3 comments

Comments

@jonathanslenders
Copy link

This is probably a bug in mypy.

It can be reproduced by creating a directory a with only two files in there: an __init__.py and b.py

 $ cat a/__init__.py
from .b import X

and

 $ cat a/b.py
# type: ignore[no-redef]
class X:
    pass
__all__ = ['X']

Mypy gives the following output:

$ mypy a/
a/__init__.py:1: error: Module 'a.b' has no attribute 'X'
Found 1 error in 1 file (checked 2 source files)

Remove the type: ignore[no-redef] and mypy succeeds.

I would not expect that ignoring something (even leaving type: ignore in there makes mypy fail), would break the imports.

This is an issue for prompt_toolkit: prompt-toolkit/python-prompt-toolkit#1008

@ilevkivskyi
Copy link
Member

Hm, this is interesting. This is an artefact of how top-level # type: ignore is implemented. I assume you are aware that per PEP 484 a # type: ignore on line of its own should ignore all errors until the end of file. This is implemented in mypy by marking code after the # type: ignore as unreachable.

So this is essentially a duplicate of #7839 (there is also a workaround mentioned).

@jonathanslenders
Copy link
Author

Thanks for the quick reply @ilevkivskyi ! I really appreciate it.

So # mypy: ignore-errors 8000 will ignore all typing errors?
Actually, I really want these files to be type checked, except for one single no-redef warning.

The code does register key bindings callbacks like this in the snippet below, and I don't like to think of hundreds of different names for functions that are never called by that name.

@handle_key('control-c')
def _():
   ...

@handle_key('control-a')
   ...

If I could configure mypy to ignore no-redef when functions are named _, that would be fine too.

Thanks again. I'll see when a fix arrives. :-)

@ilevkivskyi
Copy link
Member

Actually, I really want these files to be type checked, except for one single no-redef warning.

Yes, support for selectively silencing error codes is planned in near future (see #7599)

jonathanslenders added a commit to prompt-toolkit/python-prompt-toolkit that referenced this issue Nov 27, 2019
jonathanslenders added a commit to prompt-toolkit/python-prompt-toolkit that referenced this issue Nov 27, 2019
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
0