You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Module has no attribute" when looping over modules #11085
Even if first.att() and second.att() both exist, for module in [first, second]: module.att() results in 'Module has no attribute "att"'.
To Reproduce
Go to an empty directory
Create two files first.py and second.py, both containing just def att() -> None: pass
Create test_both.py with the following contents:
from . import first, second
def test_both -> None:
for module in [first, second]:
module.att()
touch __init__.py
Run mypy .
Expected Behavior
This should pass type inspection.
Actual Behavior
test_both.py:6: error: Module has no attribute "att"
Found 1 error in 1 file (checked 4 source files)
Your Environment
Mypy version used: 0.910
Mypy command-line flags: N/A
Mypy configuration options from mypy.ini (and other config files): N/A
Python version used: Python 3.9.6
Operating system and version: Arch Linux
Workaround
Unravel the loop:
from . importfirst, seconddeftest_first() ->None:
first.att()
deftest_second() ->None:
second.att()
Additional
Pyright seems to resolve the type to module: Union[first.py, second.py], which is an odd syntax. I don't know what the actual syntax for this would be.
Update: Looks like this might be a dupe of #1741, which was closed due to low priority. Would it be possible to bump the priority? :)
Activity
AlexWaygood commentedon Mar 31, 2022
Closing as a duplicate of #9841