Skip to content

[ty] Extend TypedDict constructor validation to union calls#24450

Draft
charliermarsh wants to merge 2 commits intomainfrom
charlie/td-union
Draft

[ty] Extend TypedDict constructor validation to union calls#24450
charliermarsh wants to merge 2 commits intomainfrom
charlie/td-union

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

Summary

Closes astral-sh/ty#3224.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Apr 6, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 6, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.21%. The number of fully passing files held steady at 79/133.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 6, 2026

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 6, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/td-union branch 2 times, most recently from 8c14980 to aa90e92 Compare April 6, 2026 16:55
@charliermarsh charliermarsh force-pushed the charlie/td-positional branch from a636d6f to a4215a8 Compare April 6, 2026 17:21
@charliermarsh charliermarsh marked this pull request as ready for review April 6, 2026 17:31
@charliermarsh charliermarsh marked this pull request as draft April 6, 2026 17:31
@charliermarsh charliermarsh marked this pull request as ready for review April 6, 2026 18:10
@charliermarsh charliermarsh force-pushed the charlie/td-positional branch from a4215a8 to 1f82053 Compare April 7, 2026 13:48
@charliermarsh charliermarsh force-pushed the charlie/td-positional branch from 1f82053 to 148dd38 Compare April 7, 2026 14:17
Comment thread crates/ty_python_semantic/src/types/infer/builder.rs Outdated
@charliermarsh charliermarsh force-pushed the charlie/td-positional branch 4 times, most recently from 49cccb4 to af3d7cf Compare April 8, 2026 17:23
@charliermarsh charliermarsh force-pushed the charlie/td-union branch 3 times, most recently from 95f73c5 to 89c461e Compare April 8, 2026 18:59
@charliermarsh charliermarsh force-pushed the charlie/td-positional branch from af3d7cf to a035944 Compare April 9, 2026 00:46
@charliermarsh charliermarsh force-pushed the charlie/td-union branch 2 times, most recently from 39d13a2 to c58b08e Compare April 9, 2026 18:53
charliermarsh added a commit that referenced this pull request Apr 9, 2026
## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

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

<!-- How was it tested? -->

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
@charliermarsh charliermarsh force-pushed the charlie/td-positional branch 2 times, most recently from 4ff83f4 to a81ac5f Compare April 14, 2026 20:54
Base automatically changed from charlie/td-positional to main April 14, 2026 21:01
ibraheemdev pushed a commit that referenced this pull request Apr 15, 2026
## Summary

<!-- What's the purpose of the change? What does it do, and why? -->

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

<!-- How was it tested? -->

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypedDict constructor validation doesn't run for unions

3 participants