[ty] Infer dict(TypedDict) as dict[str, object] by charliermarsh · Pull Request #24852 · astral-sh/ruff (original) (raw)

@astral-sh-bot Bot added the ty

Multi-file analysis & type inference

label

Apr 26, 2026

carljm

@charliermarsh

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

May 23, 2026

@charliermarsh @thejchap

Summary

Given:

from typing import TypedDict

class TD(TypedDict):
    x: int
    y: str

def _(data: TD):
    reveal_type(dict(data))

We now reveal dict[str, object].

We could consider using a narrower value type (e.g., infer dict[str, int] if all values are int), though Mypy and Pyright don't do that (I suppose it wouldn't be sound for open TypedDicts?).

Closes astral-sh/ty#3340.

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

May 28, 2026

@charliermarsh @anishgirianish

Summary

Given:

from typing import TypedDict

class TD(TypedDict):
    x: int
    y: str

def _(data: TD):
    reveal_type(dict(data))

We now reveal dict[str, object].

We could consider using a narrower value type (e.g., infer dict[str, int] if all values are int), though Mypy and Pyright don't do that (I suppose it wouldn't be sound for open TypedDicts?).

Closes astral-sh/ty#3340.

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 }})