[ty] Respect dict-compatible fallbacks in TypedDict unions by charliermarsh · Pull Request #25242 · astral-sh/ruff (original) (raw)

@astral-sh-bot Bot added the ty

Multi-file analysis & type inference

label

May 19, 2026

Base automatically changed from charlie/ty-3488-aliased-dict-fallback to main

May 19, 2026 18:58

@charliermarsh

@charliermarsh

@charliermarsh charliermarsh changed the title[ty] Recognize dict-compatible TypedDict union fallbacks [ty] Respect dict-compatible fallbacks in TypedDict unions

May 20, 2026

AlexWaygood

@charliermarsh

AlexWaygood

@charliermarsh charliermarsh deleted the charlie/ty-3488-dict-compatible-fallback branch

May 20, 2026 15:51

thejchap pushed a commit to thejchap/ruff that referenced this pull request

May 23, 2026

@charliermarsh @thejchap

…sh#25242)

Summary

Prior to this change, this snippet would produce a TypedDict-based missing-key diagnostic, because the RHS wasn't viewed as assignable to the Mapping[int, float] (since we were only gating on dict):

from typing import TypedDict, Mapping

class Foo(TypedDict):
    some: str
    name: str

mapping: Foo | Mapping[int, float] = {1: 5.2}

We now use speculative inference to determine whether the non-TypedDict union member T is a viable fallback type.

Closes astral-sh/ty#3488.

anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request

May 28, 2026

@charliermarsh @anishgirianish

…sh#25242)

Summary

Prior to this change, this snippet would produce a TypedDict-based missing-key diagnostic, because the RHS wasn't viewed as assignable to the Mapping[int, float] (since we were only gating on dict):

from typing import TypedDict, Mapping

class Foo(TypedDict):
    some: str
    name: str

mapping: Foo | Mapping[int, float] = {1: 5.2}

We now use speculative inference to determine whether the non-TypedDict union member T is a viable fallback type.

Closes astral-sh/ty#3488.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})