[ty] Synthesize __init__ for TypedDict by Glyphack · Pull Request #24476 · astral-sh/ruff (original) (raw)
Bot added the ty
Multi-file analysis & type inference
label
Glyphack changed the title
Synthesize [ty] Synthesize __init__ for TypedDict__init__ for TypedDict
Glyphack marked this pull request as ready for review
carljm removed their request for review
Glyphack deleted the shaygan-typedict-binding branch
carljm added a commit that referenced this pull request
- main:
[ty] Fix bad diagnostic range for incorrect implicit
__init_subclass__calls (#24541) [ty] Add aSupportedPythonVersionenum (#24412) [ty] Ignore unsupported editor-selected Python versions (#24498) [ty] Add snapshots for__init_subclass__diagnostics (#24539) [ty] Minor fix in tests (#24538) [ty] AllowFinalvariable assignments in__post_init__(#24529) [ty] Expand test suite for assignment errors (#24537) [ty] Usemap, not__map, as the name of the mapping parameter inTypedDict__init__methods (#24535) [ty] Rework logic for synthesizingTypedDictmethods (#24534) [flake8-bandit] Fix S103 false positives and negatives in mask analysis (#24424) [ty] mdtest.py: update dependencies (#24533) Rename patterns and arguments source order iterator method (#24532) [ty] Omit invalid keyword arguments fromTypedDictsignature (#24522) [ty] support super() in metaclass methods (#24483) [ty] Synthesize__init__forTypedDict(#24476)
carljm added a commit that referenced this pull request
- main:
Bump typing conformance suite commit to latest upstream (#24553)
[ty] Reject deleting
Finalattributes (#24508) [ty] Respect property deleters in attribute deletion checks (#24500) [ty] stop unioning Unknown into types of un-annotated attributes (#24531) [ty] Fix bad diagnostic range for incorrect implicit__init_subclass__calls (#24541) [ty] Add aSupportedPythonVersionenum (#24412) [ty] Ignore unsupported editor-selected Python versions (#24498) [ty] Add snapshots for__init_subclass__diagnostics (#24539) [ty] Minor fix in tests (#24538) [ty] AllowFinalvariable assignments in__post_init__(#24529) [ty] Expand test suite for assignment errors (#24537) [ty] Usemap, not__map, as the name of the mapping parameter inTypedDict__init__methods (#24535) [ty] Rework logic for synthesizingTypedDictmethods (#24534) [flake8-bandit] Fix S103 false positives and negatives in mask analysis (#24424) [ty] mdtest.py: update dependencies (#24533) Rename patterns and arguments source order iterator method (#24532) [ty] Omit invalid keyword arguments fromTypedDictsignature (#24522) [ty] support super() in metaclass methods (#24483) [ty] Synthesize__init__forTypedDict(#24476)
ibraheemdev pushed a commit that referenced this pull request
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 }})