Skip to content

[ty] Enable narrowing for unions of TypedDict#25188

Merged
charliermarsh merged 14 commits into
mainfrom
charlie/td-required-keys
Jun 4, 2026
Merged

[ty] Enable narrowing for unions of TypedDict#25188
charliermarsh merged 14 commits into
mainfrom
charlie/td-required-keys

Conversation

@charliermarsh

@charliermarsh charliermarsh commented May 15, 2026

Copy link
Copy Markdown
Member

Summary

See the extensive discussion in astral-sh/ty#3461. To perform sound narrowing with a union of TypedDicts after validating that a key is present, we can intersect the union with a protocol that indicates existence of the member (returning object).

Closes astral-sh/ty#3461.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 15, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 15, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 92.13%. The percentage of expected errors that received a diagnostic held steady at 87.18%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented May 15, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 15, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-key 0 1,013 2
invalid-argument-type 23 1 2
not-iterable 3 0 0
unresolved-attribute 1 0 0
unused-type-ignore-comment 1 0 0
Total 28 1,014 4

Showing a random sample of 277 of 1046 changes. See the HTML report for the full diff.

Raw diff sample (277 of 1046 changes)
core (https://github.com/home-assistant/core)
- homeassistant/components/cloud/alexa_config.py:540:45 error[invalid-key] Unknown key "old_entity_id" for TypedDict `_EventEntityRegistryUpdatedData_CreateRemove` (subscripted object has type `_EventEntityRegistryUpdatedData_CreateRemove | _EventEntityRegistryUpdatedData_Update`)
+ homeassistant/components/cloud/alexa_config.py:540:34 error[invalid-argument-type] Argument to bound method `list.append` is incorrect: Expected `str`, found `object`
+ homeassistant/config_entries.py:486:17 error[invalid-argument-type] Argument is incorrect: Expected `str`, found `object`

cwltool (https://github.com/common-workflow-language/cwltool)
- cwltool/builder.py:273:24 error[invalid-key] Unknown key "type" for TypedDict `CWLFileType` (subscripted object has type `(int & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]]) | (float & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]]) | ... omitted 3 union elements`)
- cwltool/process.py:1071:41 error[invalid-key] Unknown key "requirements" for TypedDict `CWLDirectoryType` (subscripted object has type `(MutableSequence[MutableMapping[str, int | str | float | ... omitted 5 union elements]] & Top[MutableMapping[Unknown, Unknown]]) | MutableMapping[str, int | str | float | ... omitted 5 union elements] | (int & Top[MutableMapping[Unknown, Unknown]]) | ... omitted 6 union elements`)

pydantic (https://github.com/pydantic/pydantic)
- pydantic/_internal/_schema_gather.py:115:33 error[invalid-argument-type] Argument to function `traverse_schema` is incorrect: Expected `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`, found `Unknown | str | InvalidSchema | ... omitted 51 union elements`
- pydantic/_internal/_schema_gather.py:111:29 error[invalid-argument-type] Argument to function `traverse_schema` is incorrect: Expected `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`, found `Unknown | InvalidSchema | AnySchema | ... omitted 51 union elements`
+ pydantic/_internal/_schema_gather.py:111:29 error[invalid-argument-type] Argument to function `traverse_schema` is incorrect: Expected `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`, found `object`
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `AfterValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `CallSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `ComplexSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `ComputedField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `DefinitionsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `FloatSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `LaxOrStrictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `MultiHostUrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `NoneSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `PlainSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `StringSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:111:36 error[invalid-key] Unknown key "items_schema" for TypedDict `WithDefaultSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `BeforeValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `ChainSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `CustomErrorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `DataclassArgsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `DataclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `DateSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `DatetimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `IntSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `IsSubclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `JsonOrPythonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `LaxOrStrictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `LiteralSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `MultiHostUrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `TaggedUnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `TypedDictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `UuidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:114:29 error[invalid-key] Unknown key "items_schema" for TypedDict `WrapSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
+ pydantic/_internal/_schema_gather.py:114:22 error[not-iterable] Object of type `object` is not iterable
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `ChainSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `CustomErrorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `FloatSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `IntSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `IsSubclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `ListSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `NoneSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `NullableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `PlainSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `TaggedUnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `TimedeltaSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:118:36 error[invalid-key] Unknown key "keys_schema" for TypedDict `UuidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `ArgumentsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `ComplexSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `DataclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `DefinitionReferenceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `FloatSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `FormatSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `InvalidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `JsonOrPythonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `NullableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `SimpleSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `UnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `UuidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:120:36 error[invalid-key] Unknown key "values_schema" for TypedDict `WrapValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `ChainSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `CustomErrorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `DateSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `DictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `IsInstanceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `JsonOrPythonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `LiteralSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `NullableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `StringSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:138:36 error[invalid-key] Unknown key "extras_schema" for TypedDict `WrapValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
+ pydantic/_internal/_schema_gather.py:138:29 error[invalid-argument-type] Argument to function `traverse_schema` is incorrect: Expected `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`, found `object`
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ArgumentsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `CustomErrorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `DatetimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `DefinitionsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `DictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `FloatSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `IntSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `JsonOrPythonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `LaxOrStrictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `TaggedUnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `TimedeltaSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `TupleSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:140:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `UnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `AfterValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ArgumentsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `BoolSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ComplexSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ComputedField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `DatetimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `DefinitionsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `FrozenSetSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ListSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `MultiHostUrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `PlainSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `StringSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `TaggedUnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `TupleSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:146:29 error[invalid-key] Unknown key "computed_fields" for TypedDict `UrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
+ pydantic/_internal/_schema_gather.py:146:22 error[not-iterable] Object of type `object` is not iterable
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `BoolSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `CallableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `ComplexSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `DataclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `DatetimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `DefinitionsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `DictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `LaxOrStrictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `NullableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `PlainSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `SetSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `StringSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `TaggedUnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:154:36 error[invalid-key] Unknown key "var_args_schema" for TypedDict `UuidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `BeforeValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `BoolSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `BytesSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `CallSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `ComputedField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `DataclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `DatetimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `DefinitionReferenceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `FrozenSetSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `IntSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `InvalidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `JsonOrPythonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `JsonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `NullableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `SetSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:156:36 error[invalid-key] Unknown key "var_kwargs_schema" for TypedDict `WithDefaultSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ComplexSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `DateSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `IntSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `InvalidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `IsInstanceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `LaxOrStrictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ListSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ModelSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `TimedeltaSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:163:36 error[invalid-key] Unknown key "return_schema" for TypedDict `WithDefaultSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
+ pydantic/_internal/_schema_gather.py:163:29 error[invalid-argument-type] Argument to function `traverse_schema` is incorrect: Expected `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`, found `object`
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `BytesSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `DictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `NoneSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `PlainSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `PlainValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `StringSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `TupleSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `TypedDictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:168:36 error[invalid-key] Unknown key "schema" for TypedDict `UuidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `AfterValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `BytesSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `CallSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `CallableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `DataclassArgsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `DecimalSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `GeneratorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `IsInstanceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `JsonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ModelSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `NullableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `StringSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `TaggedUnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `TypedDictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `UrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `WithDefaultSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:170:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `WrapSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `DataclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `FormatSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `IntSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `InvalidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `MultiHostUrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `NoneSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:174:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
+ pydantic/_internal/_schema_gather.py:174:29 error[invalid-argument-type] Argument to function `traverse_schema` is incorrect: Expected `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`, found `object`
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `BoolSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ComputedField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `DateSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `DefinitionReferenceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `GeneratorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ToStringSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:176:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `TypedDictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ArgumentsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ComplexSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `DataclassSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `DefinitionReferenceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `DictSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `InvalidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `IsInstanceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `JsonSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `LiteralSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `PlainValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `SimpleSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `TimedeltaSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:180:36 error[invalid-key] Unknown key "return_schema" for TypedDict `WrapValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `BoolSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `BytesSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `DataclassArgsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `DateSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `GeneratorSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `IsInstanceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `NoneSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `TimedeltaSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:182:36 error[invalid-key] Unknown key "schema" for TypedDict `TupleSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `AfterValidatorFunctionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ArgumentsV3Schema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ComputedField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `DecimalSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ModelFieldsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `ModelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `TimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `UrlSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `WithDefaultSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:184:36 error[invalid-key] Unknown key "json_schema_input_schema" for TypedDict `WrapSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `AnySchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `CallableSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `DataclassArgsSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `DateSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `DatetimeSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `DefinitionReferenceSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `EnumSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `FloatSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `FormatSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `InvalidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `LiteralSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `TimedeltaSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `TupleSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `UnionSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:187:36 error[invalid-key] Unknown key "schema" for TypedDict `UuidSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/_internal/_schema_gather.py:190:32 error[invalid-key] Unknown key "serialization" for TypedDict `WrapSerializerFunctionSerSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 56 union elements`)
- pydantic/json_schema.py:465:39 error[invalid-key] Unknown key "ref" for TypedDict `MissingSentinelSchema` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 53 union elements`)
- pydantic/json_schema.py:465:39 error[invalid-key] Unknown key "ref" for TypedDict `ModelField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 53 union elements`)
- pydantic/json_schema.py:465:39 error[invalid-key] Unknown key "ref" for TypedDict `TypedDictField` (subscripted object has type `InvalidSchema | AnySchema | NoneSchema | ... omitted 53 union elements`)

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented May 15, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 65 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing charlie/td-required-keys (37f7a02) with main (fd16b26)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh force-pushed the charlie/td-required-keys branch 2 times, most recently from c22ebe7 to 250e108 Compare May 15, 2026 22:16
Comment thread crates/ty_python_semantic/src/types/narrow.rs Outdated
@charliermarsh charliermarsh force-pushed the charlie/td-required-keys branch from ac900be to d98fa0e Compare May 15, 2026 22:23
@charliermarsh charliermarsh changed the title [ty] View ecosystem results for synthesized TypedDict intersection [ty] Enable narrowing for unions of TypedDict May 15, 2026
@charliermarsh charliermarsh marked this pull request as ready for review May 15, 2026 22:25
@astral-sh-bot astral-sh-bot Bot requested a review from AlexWaygood May 15, 2026 22:25
Comment thread crates/ty_python_semantic/src/types/narrow.rs Outdated
Comment thread crates/ty_python_semantic/resources/mdtest/typed_dict.md Outdated
@charliermarsh charliermarsh marked this pull request as draft May 15, 2026 22:35
@charliermarsh charliermarsh force-pushed the charlie/td-required-keys branch 5 times, most recently from da109f4 to 8802453 Compare May 15, 2026 23:11
@@ -1412,11 +1414,38 @@ impl<'db, 'ast> NarrowingConstraintsBuilder<'db, 'ast> {
&& let rhs_type = inference.expression_type(&comparators[0])
&& is_or_contains_typeddict(self.db, rhs_type)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary, but retaining it to avoid protocol in the type display where it isn't required.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can obviously gate the logic further (e.g., avoid intersecting with a Literal within a Union, etc.) if we want.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I did that part too because it was bothering me :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, worryingly, adding this is_or_contains_typeddict gate (I removed it in a prior commit) materially changed the diagnostics:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should try broadening this, it would be much more principled. But let's see about improving our subtyping and disjointness for these synthesized protocols first. And it could also have performance implications, so best done as a followup.

@charliermarsh charliermarsh marked this pull request as ready for review May 15, 2026 23:12
@astral-sh-bot astral-sh-bot Bot requested a review from AlexWaygood May 15, 2026 23:12
@charliermarsh charliermarsh force-pushed the charlie/td-required-keys branch from 30f01eb to 08145e0 Compare May 15, 2026 23:22

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread crates/ty_python_semantic/src/types/narrow.rs
Comment on lines +4553 to +4556
def literal_union(u: Foo | Literal["abc"]):
if "a" in u:
# revealed: (Foo & <Protocol with members '__getitem__'>) | (Literal["abc"] & <Protocol with members '__getitem__'>)
reveal_type(u)

@AlexWaygood AlexWaygood May 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, this does reveal a problem with the approach I was suggesting... just because "a" in obj resolves to True doesn't necessarily mean that obj["a"] is a valid operation. "abc"["a"] fails at runtime even though "a" in "abc" resolves to True.

I think maybe that does suggest that something more similar to one of your earlier approaches might be better... for a TypedDict (as a standalone type or a union member), we want to intersect with a protocol that has a __getitem__(self, key: Literal["a"]) -> object method. But for any non-TypedDict, we probably just want to intersect with a protocol that has a __contains__(self, key: Literal["a"]) -> Literal[True]. Intersecting with the __getitem__ protocol is only safe for TypedDict types, not for other types.

In retrospect this feels obvious. Sorry for sending you round the houses on this, that only occurred to me now :-(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol how did we not notice this

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's also unsafe for dict and other types due to subclassing?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably do it for any subtype of Mapping[str, object]? Strictly speaking, you could create a subtype of Mapping with a naughty __contains__ method. But that's not really what you're supposed to do -- the expectation is that all mappings are going to behave in such a way that if "foo" in mapping evaluates to True, therefore mapping["foo"] will not raise KeyError. I think it would be okay to assume that all subclasses of Mapping are "reasonable subclasses", in a similar way to the way we assume in many places elsewhere that the Liskov Substitution Principle is never violated.

The solution you have already implemented only works for TypedDicts, though (because you're intersecting with TypedDicts rather than with synthesized Protocols), so let's land what you have now to make progress here. We can experiment with broadening it to Mappings in general in a followup if we feel like it; it's probably much less important anyway

.iter()
.map(|element| self.narrow_with_present_key(*element, key)),
),
resolved if is_or_contains_typeddict(self.db, resolved) => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I believe is_or_contains_typeddict in this case is just checking for Type::TypedDict and intersections, since unions should be covered by the above. We could use a separate check but doesn't feel critical.)

@charliermarsh charliermarsh force-pushed the charlie/td-required-keys branch from 9a9d64b to 2d8d195 Compare May 30, 2026 14:07
@charliermarsh charliermarsh force-pushed the charlie/td-required-keys branch from 2d8d195 to 75f3aed Compare May 30, 2026 16:39
@charliermarsh charliermarsh marked this pull request as draft May 30, 2026 20:41
@charliermarsh

Copy link
Copy Markdown
Member Author

Disaster, this seemingly doesn't work after we added the TypedDict.__getitem__(str) -> object fallback.

@charliermarsh

Copy link
Copy Markdown
Member Author

Somehow gets simplified out in the constraint solver.

@charliermarsh

Copy link
Copy Markdown
Member Author

The current version intersects TypedDicts with a synthetic TypedDict, and non-TypedDicts with the __contains__ protocol mentioned earlier...

@charliermarsh charliermarsh marked this pull request as ready for review May 30, 2026 21:04
@astral-sh-bot astral-sh-bot Bot requested a review from AlexWaygood May 30, 2026 21:04

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I pushed a small simplification

Comment on lines +4553 to +4556
def literal_union(u: Foo | Literal["abc"]):
if "a" in u:
# revealed: (Foo & <Protocol with members '__getitem__'>) | (Literal["abc"] & <Protocol with members '__getitem__'>)
reveal_type(u)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably do it for any subtype of Mapping[str, object]? Strictly speaking, you could create a subtype of Mapping with a naughty __contains__ method. But that's not really what you're supposed to do -- the expectation is that all mappings are going to behave in such a way that if "foo" in mapping evaluates to True, therefore mapping["foo"] will not raise KeyError. I think it would be okay to assume that all subclasses of Mapping are "reasonable subclasses", in a similar way to the way we assume in many places elsewhere that the Liskov Substitution Principle is never violated.

The solution you have already implemented only works for TypedDicts, though (because you're intersecting with TypedDicts rather than with synthesized Protocols), so let's land what you have now to make progress here. We can experiment with broadening it to Mappings in general in a followup if we feel like it; it's probably much less important anyway


def literal_union_key_access(obj: Foo | Literal["a"]):
if "a" in obj:
# Membership in a string does not imply that the string supports subscripting with that key.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

Comment on lines +2153 to +2155
let constrain = |ty, key_presence_constraint| {
IntersectionType::from_two_elements(db, ty, key_presence_constraint)
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit weird here that we do an intersection here internally but then using a NarrowingConstraint::replacement() at the callsite -- why not just return just the type you want to intersect with from this method and then use NarrowingConstraint::intersection()! But I played around with it briefly and it didn't do what I wanted it to, so let's not worry about that too much for now. (It could maybe be worth a TODO in the code, I guess.)

@charliermarsh charliermarsh enabled auto-merge (squash) June 4, 2026 19:05
@charliermarsh charliermarsh merged commit 0fd91a4 into main Jun 4, 2026
58 checks passed
@charliermarsh charliermarsh deleted the charlie/td-required-keys branch June 4, 2026 19:11
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.

Positive TypedDict key membership does not make key access safe

2 participants