Skip to content

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

@jonathanslenders

Description

@jonathanslenders

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

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