-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normaltopic-disallow-anyThe disallow-any-* family of flagsThe disallow-any-* family of flagstopic-type-ignore# type: ignore comments# type: ignore comments
Description
In our mypy config file we do not allow Any
to be used. Because this cannot be avoided all the time we use #type: ignore[misc]
at the top of a module.
We created a module called typing.py
.
# type: ignore[misc] # Ignores 'Any' input parameter
from typing import Any, Iterable
JsonSerializable = Any
CsvSerializable = Iterable[Any]
This is imported in another module.
from my_app.typing import JsonSerializable
def foo(data: JsonSerializable) -> None:
...
Actual result
PS C:\workspace\my_app> mypy
src\my_app\foo.py:6: error: Module 'my_app.typing' has no attribute 'JsonSerializable' [attr-defined]
from my_app.typing import JsonSerializable
Found 1 errors in 1 files (checked 6 source files)
Expected result
PS C:\workspace\my_app> mypy
Success: no issues found in 6 source files
How did we solve it?
When we change typing.py
so it ignores Any
on each line we don't have any issues.
from typing import Any, Iterable
JsonSerializable = Any # type: ignore[misc] # Ignores 'Any' input parameter
CsvSerializable = Iterable[Any] # type: ignore[misc] # Ignores 'Any' input parameter
Configuration
- Python 3.8.2
- Mypy 0.782
- Windows 10
- Not in a virtualenv
.mypy.ini
[mypy]
python_version = 3.8
disallow_any_expr = False
disallow_any_decorated = False
disallow_any_explicit = True
disallow_any_generics = True
disallow_subclassing_any = True
disallow_untyped_calls = True
disallow_untyped_defs = True
check_untyped_defs = False
disallow_untyped_decorators = False
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
warn_return_any = True
warn_unreachable = True
strict_equality = True
allow_redefinition = False
imran-mumtaz, RomainMuller, MetRonnie, aliaksandr-tsukanau, tuukkamustonen and 6 more
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongpriority-1-normaltopic-disallow-anyThe disallow-any-* family of flagsThe disallow-any-* family of flagstopic-type-ignore# type: ignore comments# type: ignore comments