Skip to content

Bidirectional type inference with unions #1266

@ibraheemdev

Description

@ibraheemdev

This snippet currently type-checks:

from typing import TypedDict, overload, reveal_type

class T(TypedDict):
  x: int


def f(x: T): ...

x: T | int = { "y": 1 }
reveal_type(x)

Bi-directional type-inference doesn't see through the union, so we infer dict[Unknown | str, Unknown | int]. We also don't end up validating the TypedDict constructor.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions