[ty] Respect dict-compatible fallbacks in TypedDict unions by charliermarsh · Pull Request #25242 · astral-sh/ruff (original) (raw)
Bot added the ty
Multi-file analysis & type inference
label
Base automatically changed from charlie/ty-3488-aliased-dict-fallback to main
charliermarsh changed the title
[ty] Recognize dict-compatible TypedDict union fallbacks [ty] Respect dict-compatible fallbacks in TypedDict unions
charliermarsh deleted the charlie/ty-3488-dict-compatible-fallback branch
thejchap pushed a commit to thejchap/ruff that referenced this pull request
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
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 }})