Skip to content

Errors when using defaultdict #995

Closed
@rowillia

Description

@rowillia

defaultdict's documentation suggests passing list as an argument to defaultdict - https://docs.python.org/2/library/collections.html#defaultdict-examples

mypy complains when I do this however

from collections import defaultdict

foo = defaultdict(list)
bar = defaultdict(dict)

Results in:

default_dict_example.py, line 3: Argument 1 to "defaultdict" has incompatible type List[_T]; expected Callable[[], List[_T]]
default_dict_example.py, line 3: Need type annotation for variable
default_dict_example.py, line 4: Argument 1 to "defaultdict" has incompatible type Dict[_KT, _VT]; expected Callable[[], Dict[_KT, _VT]]
default_dict_example.py, line 4: Need type annotation for variable

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions