[ty] Add precisely-typed overloads for TypedDict update#24101
[ty] Add precisely-typed overloads for TypedDict update#24101charliermarsh merged 5 commits intomainfrom
TypedDict update#24101Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 85.38%. The percentage of expected errors that received a diagnostic held steady at 78.70%. The number of fully passing files held steady at 64/132. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
47 | 0 | 0 |
unused-type-ignore-comment |
0 | 1 | 0 |
| Total | 47 | 1 | 0 |
Raw diff (48 changes)
core (https://github.com/home-assistant/core)
+ homeassistant/components/forked_daapd/config_flow.py:194:29 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'alternative_domain', 'configuration_url', 'confirm_only', 'discovery_key', 'dismiss_protected', 'entry_id', 'show_advanced_options', 'source', 'title_placeholders', 'unique_id'> | Iterable[tuple[str, object]]`, found `dict[str, dict[str, str | int | None | Any]]`
+ homeassistant/components/forked_daapd/config_flow.py:194:52 error[invalid-argument-type] Invalid argument to key "title_placeholders" with declared type `Mapping[str, str]` on TypedDict `<TypedDict with items 'alternative_domain', 'configuration_url', 'confirm_only', 'discovery_key', 'dismiss_protected', 'entry_id', 'show_advanced_options', 'source', 'title_placeholders', 'unique_id'>`: value of type `dict[str, str | int | None | Any]`
discord.py (https://github.com/Rapptz/discord.py)
- discord/onboarding.py:156:92 warning[unused-type-ignore-comment] Unused blanket `type: ignore` directive
pydantic (https://github.com/pydantic/pydantic)
+ pydantic/_internal/_generate_schema.py:2797:46 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'schema_ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2804:46 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'schema_ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'allow_inf_nan', 'decimal_places', 'ge', 'gt', 'le', 'lt', 'max_digits', 'metadata', 'multiple_of', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'allow_inf_nan', 'ge', 'gt', 'le', 'lt', 'metadata', 'multiple_of', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'allowed_schemes', 'default_host', 'default_path', 'default_port', 'host_required', 'max_length', 'metadata', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'arguments_schema', 'extra_behavior', 'metadata', 'ref', 'serialization', 'type', 'validate_by_alias', 'validate_by_name'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'arguments_schema', 'function', 'function_name', 'metadata', 'ref', 'return_schema', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'arguments_schema', 'metadata', 'ref', 'serialization', 'type', 'validate_by_alias', 'validate_by_name', 'var_args_schema', 'var_kwargs_mode', 'var_kwargs_schema'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'auto_collapse', 'choices', 'custom_error_context', 'custom_error_message', 'custom_error_type', 'metadata', 'mode', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'choices', 'custom_error_context', 'custom_error_message', 'custom_error_type', 'discriminator', 'from_attributes', 'metadata', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'cls', 'cls_name', 'computed_fields', 'config', 'extra_behavior', 'extras_schema', 'fields', 'metadata', 'ref', 'serialization', 'strict', 'total', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'cls', 'cls_name', 'config', 'fields', 'frozen', 'generic_origin', 'metadata', 'post_init', 'ref', 'revalidate_instances', 'schema', 'serialization', 'slots', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'cls', 'cls_repr', 'metadata', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'cls', 'config', 'custom_init', 'extra_behavior', 'frozen', 'generic_origin', 'metadata', 'post_init', 'ref', 'revalidate_instances', 'root_model', 'schema', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'cls', 'members', 'metadata', 'missing', 'ref', 'serialization', 'strict', 'sub_type', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'coerce_numbers_to_str', 'max_length', 'metadata', 'min_length', 'pattern', 'ref', 'regex_engine', 'serialization', 'strict', 'strip_whitespace', 'to_lower', 'to_upper', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'collect_init_only', 'computed_fields', 'dataclass_name', 'extra_behavior', 'fields', 'metadata', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'computed_fields', 'extra_behavior', 'extras_keys_schema', 'extras_schema', 'fields', 'from_attributes', 'metadata', 'model_name', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'custom_error_context', 'custom_error_message', 'custom_error_type', 'metadata', 'ref', 'schema', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'default', 'default_factory', 'default_factory_takes_data', 'metadata', 'on_error', 'ref', 'schema', 'serialization', 'strict', 'type', 'validate_default'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'definitions', 'metadata', 'schema', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'expected', 'metadata', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'fail_fast', 'items_schema', 'max_length', 'metadata', 'min_length', 'ref', 'serialization', 'strict', 'type', 'variadic_item_index'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'fail_fast', 'items_schema', 'max_length', 'metadata', 'min_length', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'fail_fast', 'keys_schema', 'max_length', 'metadata', 'min_length', 'ref', 'serialization', 'strict', 'type', 'values_schema'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'function', 'json_schema_input_schema', 'metadata', 'ref', 'schema', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'function', 'json_schema_input_schema', 'metadata', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'function', 'metadata', 'ref', 'schema', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'ge', 'gt', 'le', 'lt', 'metadata', 'microseconds_precision', 'now_op', 'now_utc_offset', 'ref', 'serialization', 'strict', 'type', 'tz_constraint'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'ge', 'gt', 'le', 'lt', 'metadata', 'microseconds_precision', 'ref', 'serialization', 'strict', 'type', 'tz_constraint'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'ge', 'gt', 'le', 'lt', 'metadata', 'microseconds_precision', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'ge', 'gt', 'le', 'lt', 'metadata', 'multiple_of', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'ge', 'gt', 'le', 'lt', 'metadata', 'now_op', 'now_utc_offset', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'items_schema', 'max_length', 'metadata', 'min_length', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'json_schema', 'metadata', 'python_schema', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'lax_schema', 'metadata', 'ref', 'serialization', 'strict', 'strict_schema', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'max_length', 'metadata', 'min_length', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'schema', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'schema', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'schema_ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'serialization', 'steps', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'serialization', 'strict', 'type', 'version'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'serialization', 'strict', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'ref', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`
+ pydantic/_internal/_generate_schema.py:2822:23 error[invalid-argument-type] Argument is incorrect: Expected `<TypedDict with items 'metadata', 'serialization', 'type'> | Iterable[tuple[str, object]]`, found `InvalidSchema | AnySchema | NoneSchema | ... omitted 49 union elements`ae365b3 to
980c653
Compare
carljm
left a comment
There was a problem hiding this comment.
Thank you!
I think we should add support for the additional call forms mentioned inline.
|
|
||
| Type::Callable(CallableType::new( | ||
| db, | ||
| CallableSignature::from_overloads([positional_update, keyword_update]), |
There was a problem hiding this comment.
There are some other valid dict.update call forms we aren't accounting for here, so this PR regresses our current (overly lax) "support" for them:
- sequence of pairs:
x.update([("name", "Foo")]) - positional and keyword both:
x.update(patch_dict, name="Foo")
It looks like mypy does not support the first, but other type checkers do. Seems like nobody supports the second, but it is valid at runtime (and doesn't seem that hard to support?)
There was a problem hiding this comment.
For the first form, are you expecting that we'd reject (e.g.) invalid names and types? Or just validate the general argument type?
There was a problem hiding this comment.
I'd check what other type checkers do; easy to do with multiplay. I suspect this form is rarely used with a literal argument (why wouldn't you just use keyword arguments or a dict in that case?), so I suspect there's not much to be gained in being too precise with it.
980c653 to
8952548
Compare
Merging this PR will degrade performance by 6.92%
Performance Changes
Comparing Footnotes
|
8952548 to
9d0c63b
Compare
* main: (36 commits) [ty] Reduce diagnostic range for `invalid-metaclass` (#24145) [ty] Simplify TypeVar assignability/subtyping logic (#24138) [ty] Prevent tainted loop bindings in cycle normalization (#24143) [ty] Add precisely-typed overloads for `TypedDict` update (#24101) [ty] Fix folding ranges of comments separated by statements (#24132) Bump ecosystem-analyzer pin (#24136) Bump ecosystem-analyzer pin (#24135) Simplify `NewType` handling in `relation.rs` (#24109) [ty] Add more tests for `NewType` subtyping (#24115) [ty] Add `NewType`s to the property tests (#24113) [ty] Prepare test files for unreachable code change (#24133) `analyze graph`: resolve string imports that reference attributes, not just modules (#24058) Update Artifact GitHub Actions dependencies (#24116) Update taiki-e/install-action action to v2.68.33 (#24130) Update taiki-e/install-action action to v2.68.32 (#24123) Update Rust crate serde_with to v3.18.0 (#24126) Update Swatinem/rust-cache action to v2.9.1 (#24127) Update Rust crate quick-junit to 0.6.0 (#24125) Update Rust crate clap to v4.6.0 (#24124) Update Rust crate tracing-subscriber to v0.3.23 (#24122) ...
Summary
This TODO led to some false positives in #24092, so putting this up separately.
I believe the ecosystem diagnostics are false positives (and the Pydantic diagnostics in particular already have
# pyright: ignore).