Open
Description
Bug Report
When an exception is caught from a block with a single import statement, one can be certain that the import failed (right?).
When an import fails, a to-be-imported function is not defined.
If a function is not defined, mypy
should not issue a no-redef
message.
To Reproduce
pip install overrides
"""Feature request: detect failed imports and suppress no-redef."""
try:
from overrides import overrides
except ModuleNotFoundError:
# mypy issues no-redef
def overrides() -> None:
pass
print(overrides)
Expected Behavior
No message
Actual Behavior
bug.py:5: error: Name "overrides" already defined (possibly by an import) [no-redef]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: mypy 0.982 (compiled: yes)
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.10.8