[ty] Synthesize __init__ for TypedDict by Glyphack · Pull Request #24476 · astral-sh/ruff (original) (raw)

@astral-sh-bot Bot added the ty

Multi-file analysis & type inference

label

Apr 7, 2026

@Glyphack Glyphack changed the titleSynthesize __init__ for TypedDict [ty] Synthesize __init__ for TypedDict

Apr 7, 2026

@Glyphack Glyphack marked this pull request as ready for review

April 9, 2026 05:54

@carljm carljm removed their request for review

April 9, 2026 05:56

charliermarsh

charliermarsh

@charliermarsh

@Glyphack Glyphack deleted the shaygan-typedict-binding branch

April 10, 2026 04:31

carljm added a commit that referenced this pull request

Apr 10, 2026

@carljm

carljm added a commit that referenced this pull request

Apr 10, 2026

@carljm

ibraheemdev pushed a commit that referenced this pull request

Apr 15, 2026

Summary

This PR adds a synthesized __init__ method for TypedDict that is used in server for hover.

The new method is not used for type checking. The reason is that the current sophisticated validation logic has better UX than normal argument matching.

The __init__ method has two bindings right now:

class Movie(TypedDict):
    title: str
    year: int

class Movie(
    __map: Movie,
    /,
    *,
    title: str = ...,
    year: int = ...
)

class Movie(
    *,
    title: str = ...,
    year: int = ...
)

I removed the previous TODO to use synthesized method for type checking since this is being implemented with another solution. #24450.

Test Plan


Co-authored-by: Charlie Marsh charlie.r.marsh@gmail.com

This was referenced

Apr 27, 2026

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