Skip to content

Incompatible types in assignment for dict[key] = tmp = value and nested structures #5289

Open
@pmhahn

Description

@pmhahn

I have Python2 code building some nested structures like lists/tuples/sets/dicts in dicts. For populating the nested structure I keep a temporary reference, which mypy fails to parse if the (untyped) temporary reference is not the first variable being assigned:

#!/usr/bin/python2.7
from typing import Dict, Set  # noqa
x = {}  # type: Dict[str, Set[str]]
z = x[''] = set()  # okay
x[''] = y = set()  # fail: Incompatible types in assignment (expression has type "Set[<nothing>]", target has type "Set[str]")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions