Skip to content

No type inference for dicts in union #6463

@ikonst

Description

@ikonst
from typing import *

def foo() -> Dict[str, Any]:
    return {}

def bar() -> Union[Dict[str, Any], Dict[int, Any]]:
    return {}

In foo, {} is inferred as Dict[str, Any].
In bar, I get:

error: Incompatible return value type (got "Dict[<nothing>, <nothing>]", expected "Union[Dict[str, Any], Dict[int, Any]]")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions