Open
Description
Bug Report
Suppose you have the following directory tree:
thebug/
thebug/run.py
thebug/__init__.py
thebug/thebug.py
Attempting to import anything from thebug.py
(using from thebug import whatever
) will cause mypy to complain error: Module "thebug" has no attribute "whatever" [attr-defined]
.
To Reproduce
mkdir thebug
cd thebug
touch __init__.py
vim thebug.py
and type in the following contents:
class A:
def __init__(self) -> None:
self.val = "a"
vim run.py
and type in the following contents:
from thebug import A
var: A = A()
print(var.val)
- Run it to make sure it works:
$ python3 run.py
a
- Type-check it:
mypy run.py
Actual Behavior
$ mypy run.py
run.py:1: error: Module "thebug" has no attribute "A" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.16.1
- Mypy command-line flags: none, as shown above
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.12.3