KEMBAR78
`OrderedDict` fails disallow_any_generics, but `OrderedDict[Any, Any]` doesn't run · Issue #7539 · python/mypy · GitHub
Skip to content

OrderedDict fails disallow_any_generics, but OrderedDict[Any, Any] doesn't run #7539

@l0b0

Description

@l0b0

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:
    pass

This 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:
    pass

This 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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions