Skip to content

Bidirectional inference for named expressions #3124

@carljm

Description

@carljm

We don't do multi-inference for walrus expressions, which causes bugs like this:

from typing import TypedDict, Any

class Inner(TypedDict):
    x: int

class Outer(TypedDict):
    inner: Inner

d1: Outer | dict[str, Any] = {"inner": {"x": 1}}
d2: Outer | dict[str, Any] = {"inner": (inner := {"x": 1})}

reveal_type(d1)  # Outer
reveal_type(d2)  # dict[str, Any]

https://play.ty.dev/f0dee682-cfe9-4c79-b6b9-6f7b7215f023

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions