-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
I've been trying to introduce disallow_any_generics = true to an already extensively typed code base of ~48kSLOC, and the only remaining issue is typing OrderedDicts.
Actual behaviour
Given this configuration:
[mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_untyped_defs = true
ignore_missing_imports = true
no_implicit_optional = true
warn_redundant_casts = true
warn_return_any = true
warn_unused_ignores = true
Code with implicit Any:
from collections import OrderedDict
from typing import Any
def name(value: OrderedDict) -> None:
passThis fails validation because of disallow_any_generics = true:
$ mypy example.py
example.py:4: error: Missing type parameters for generic type
Code with typed OrderedDict:
from collections import OrderedDict
from typing import Any
def name(value: OrderedDict[Any, Any]) -> None:
passThis passes validation, but doesn't run:
$ python example.py
Traceback (most recent call last):
File "example.py", line 4, in <module>
def name(value: OrderedDict[Any, Any]) -> None:
TypeError: 'type' object is not subscriptable
Versions:
$ python --version
Python 3.6.8
$ mypy --version
mypy 0.720
(Also failed on mypy 0.711.)
Expected behaviour
I'd expect either the first snippet to be valid or the second snippet to run. As it is I'm stuck for how to proceed.
sambonner