ruff/crates/ty_python_semantic/resources
David Peter 2f6f3e1042
[ty] Faster subscript assignment checks for (unions of) TypedDicts (#21378)
## Summary

We synthesize a (potentially large) set of `__setitem__` overloads for
every item in a `TypedDict`. Previously, validation of subscript
assignments on `TypedDict`s relied on actually calling `__setitem__`
with the provided key and value types, which implied that we needed to
do the full overload call evaluation for this large set of overloads.
This PR improves the performance of subscript assignment checks on
`TypedDict`s by validating the assignment directly instead of calling
`__setitem__`.

This PR also adds better handling for assignments to subscripts on union
and intersection types (but does not attempt to make it perfect). It
achieves this by distributing the check over unions and intersections,
instead of calling `__setitem__` on the union/intersection directly. We
already do something similar when validating *attribute* assignments.

## Ecosystem impact

* A lot of diagnostics change their rule type, and/or split into
multiple diagnostics. The new version is more verbose, but easier to
understand, in my opinion
* Almost all of the invalid-key diagnostics come from pydantic, and they
should all go away (including many more) when we implement
https://github.com/astral-sh/ty/issues/1479
* Everything else looks correct to me. There may be some new diagnostics
due to the fact that we now check intersections.

## Test Plan

New Markdown tests.
2025-11-12 20:16:38 +01:00
..
corpus [ty] fix global symbol lookup from eager scopes (#21317) 2025-11-12 10:15:51 -08:00
mdtest [ty] Faster subscript assignment checks for (unions of) TypedDicts (#21378) 2025-11-12 20:16:38 +01:00
primer [ty] Add cycle handling to lazy_default (#20967) 2025-10-23 10:05:08 +02:00
README.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00

Markdown files within the mdtest/ subdirectory are tests of type inference and type checking; executed by the tests/mdtest.rs integration test.

See crates/ty_test/README.md for documentation of this test format.