Skip to content

mypy does not warn about incorrect default value in dict.get in some case #9128

Open
@mmohrhard

Description

@mmohrhard

It seems that mypy should actually warn about the assignment of the set in the following code:

from typing import Dict, Any

params: Dict[str, Any] = {}
a: Dict[str, Any] = params.get("abc", set())
reveal_type(a)

mypy does not warn about the incorrect assignment of Set to a but correctly reveals that the type of a is Dict[str, Any]. Sadly the use of Any in this case is common as these dicts represent complex configuration files.

Tested with the current git master version.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions