Skip to content

Support assignment to union of TypedDict #2265

@ibraheemdev

Description

@ibraheemdev

We currently only consider the type context if there is a single TypedDict element. We should support the following:

from typing import TypedDict

class Foo(TypedDict):
    foo: int

class Bar(TypedDict):
    bar: int

x: Foo | Bar = reveal_type({ "foo": 1 }) # Foo

class FooBar1(TypedDict):
    foo: int
    bar: int

class FooBar2(TypedDict):
    foo: int
    bar: int

x: FooBar1 | FooBar2 = reveal_type({ "foo": 1, "bar": 1 }) # FooBar1 | FooBar2

Metadata

Metadata

Assignees

Labels

bidirectional inferenceInference of types that takes into account the context of a declared type or expected typetypeddict

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions