Skip to content

[ty] Faster subscript assignment checks for (unions of) TypedDicts#21378

Merged
sharkdp merged 4 commits intomainfrom
david/faster-subscript-assignment-checks
Nov 12, 2025
Merged

[ty] Faster subscript assignment checks for (unions of) TypedDicts#21378
sharkdp merged 4 commits intomainfrom
david/faster-subscript-assignment-checks

Conversation

@sharkdp
Copy link
Contributor

@sharkdp sharkdp commented Nov 11, 2025

Summary

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

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

Ecosystem impact

  • A lot of diagnostics change their rule type, and/or split into multiple diagnostics. The new version is more verbose, but easier to understand, in my opinion
  • Almost all of the invalid-key diagnostics come from pydantic, and they should all go away (including many more) when we implement Implement "tagged union" narrowing for namedtuples and arbitrary nominal types ty#1479
  • Everything else looks correct to me. There may be some new diagnostics due to the fact that we now check intersections.

Test Plan

New Markdown tests.

@sharkdp sharkdp added ty Multi-file analysis & type inference performance Potential performance improvement labels Nov 11, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 11, 2025

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests
--- old-output.txt	2025-11-12 15:50:26.056135771 +0000
+++ new-output.txt	2025-11-12 15:50:29.708160055 +0000
@@ -745,7 +745,7 @@
 namedtuples_usage.py:34:7: error[index-out-of-bounds] Index 3 is out of bounds for tuple `Point` with length 3
 namedtuples_usage.py:35:7: error[index-out-of-bounds] Index -4 is out of bounds for tuple `Point` with length 3
 namedtuples_usage.py:40:1: error[invalid-assignment] Cannot assign to read-only property `x` on object of type `Point`
-namedtuples_usage.py:41:1: error[invalid-assignment] Cannot assign to object of type `Point` with no `__setitem__` method
+namedtuples_usage.py:41:1: error[invalid-assignment] Cannot assign to a subscript on an object of type `Point` with no `__setitem__` method
 namedtuples_usage.py:52:1: error[invalid-assignment] Too many values to unpack: Expected 2
 namedtuples_usage.py:53:1: error[invalid-assignment] Not enough values to unpack: Expected 4
 narrowing_typeguard.py:17:9: error[type-assertion-failure] Argument does not have asserted type `tuple[str, str]`
@@ -971,7 +971,7 @@
 typeddicts_extra_items.py:339:1: error[type-assertion-failure] Argument does not have asserted type `tuple[str, int]`
 typeddicts_extra_items.py:339:13: error[unresolved-attribute] Object of type `IntDictWithNum` has no attribute `popitem`
 typeddicts_extra_items.py:342:27: error[invalid-key] Cannot access `IntDictWithNum` with a key of type `str`. Only string literals are allowed as keys on TypedDicts.
-typeddicts_extra_items.py:343:31: error[invalid-key] Invalid key for TypedDict `IntDictWithNum` of type `str`
+typeddicts_extra_items.py:343:31: error[invalid-key] Invalid key of type `str` for TypedDict `IntDictWithNum`
 typeddicts_extra_items.py:352:5: error[invalid-assignment] Object of type `dict[str, int]` is not assignable to `IntDict`
 typeddicts_operations.py:22:17: error[invalid-assignment] Invalid assignment to key "name" with declared type `str` on TypedDict `Movie`: value of type `Literal[1982]`
 typeddicts_operations.py:23:17: error[invalid-assignment] Invalid assignment to key "year" with declared type `int` on TypedDict `Movie`: value of type `Literal[""]`

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 11, 2025

mypy_primer results

Changes were detected when running on open source projects
more-itertools (https://github.com/more-itertools/more-itertools)
- more_itertools/more.py:5392:21: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | list[Unknown | None] | None` may be missing
- more_itertools/more.py:5393:21: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | list[Unknown | None] | None` may be missing
+ more_itertools/more.py:5392:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ more_itertools/more.py:5393:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method

parso (https://github.com/davidhalter/parso)
- parso/pgen2/generator.py:100:9: error[invalid-assignment] Cannot assign to object of type `Mapping[str, DFAState[Unknown]]` with no `__setitem__` method
+ parso/pgen2/generator.py:100:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `Mapping[str, DFAState[Unknown]]` with no `__setitem__` method
- parso/pgen2/generator.py:105:17: error[invalid-assignment] Cannot assign to object of type `Mapping[str, DFAState[Unknown]]` with no `__setitem__` method
+ parso/pgen2/generator.py:105:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `Mapping[str, DFAState[Unknown]]` with no `__setitem__` method

spack (https://github.com/spack/spack)
- lib/spack/spack/vendor/macholib/MachO.py:405:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | list[Unknown]` may be missing
+ lib/spack/spack/vendor/macholib/MachO.py:405:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method

stone (https://github.com/dropbox/stone)
- stone/ir/data_types.py:1121:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown, Unknown]` may be missing
- stone/ir/data_types.py:1223:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | OrderedDict[Unknown, Unknown]` may be missing
- stone/ir/data_types.py:1259:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | OrderedDict[Unknown, Unknown]` may be missing
+ stone/ir/data_types.py:1121:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ stone/ir/data_types.py:1223:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ stone/ir/data_types.py:1259:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- stone/ir/data_types.py:1275:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | OrderedDict[Unknown, Unknown]` may be missing
+ stone/ir/data_types.py:1275:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- stone/ir/data_types.py:1483:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | OrderedDict[Unknown, Unknown]` may be missing
+ stone/ir/data_types.py:1483:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- stone/ir/data_types.py:1509:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | OrderedDict[Unknown, Unknown]` may be missing
- stone/ir/data_types.py:1515:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | OrderedDict[Unknown, Unknown]` may be missing
+ stone/ir/data_types.py:1509:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ stone/ir/data_types.py:1515:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method

werkzeug (https://github.com/pallets/werkzeug)
- src/werkzeug/utils.py:91:13: error[invalid-assignment] Cannot assign to object of type `object` with no `__setitem__` method
+ src/werkzeug/utils.py:91:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `object` with no `__setitem__` method
- tests/test_routing.py:604:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | Mapping[str, Any] | None` may be missing
+ tests/test_routing.py:604:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `Mapping[str, Any]` with no `__setitem__` method
+ tests/test_routing.py:604:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- Found 408 diagnostics
+ Found 409 diagnostics

pip (https://github.com/pypa/pip)
- src/pip/_vendor/requests/models.py:549:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | CaseInsensitiveDict` may be missing
- src/pip/_vendor/requests/models.py:551:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | CaseInsensitiveDict` may be missing
+ src/pip/_vendor/requests/models.py:549:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ src/pip/_vendor/requests/models.py:551:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- src/pip/_vendor/requests/models.py:568:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | CaseInsensitiveDict` may be missing
- src/pip/_vendor/requests/models.py:579:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | CaseInsensitiveDict` may be missing
+ src/pip/_vendor/requests/models.py:568:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ src/pip/_vendor/requests/models.py:579:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- src/pip/_vendor/requests/models.py:586:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | CaseInsensitiveDict` may be missing
- src/pip/_vendor/requests/models.py:628:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | CaseInsensitiveDict` may be missing
+ src/pip/_vendor/requests/models.py:586:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ src/pip/_vendor/requests/models.py:628:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method

twine (https://github.com/pypa/twine)
+ twine/package.py:264:38: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 10 diagnostics
+ Found 11 diagnostics

scrapy (https://github.com/scrapy/scrapy)
- tests/test_http2_client_protocol.py:114:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | dict[Unknown, Unknown] | str` may be missing
+ tests/test_http2_client_protocol.py:114:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- tests/test_logformatter.py:187:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `dict[str, Any] | tuple[Any, ...]` may be missing
+ tests/test_logformatter.py:187:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `tuple[Any, ...]` with no `__setitem__` method

paasta (https://github.com/yelp/paasta)
- paasta_tools/paastaapi/api_client.py:713:21: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown, Unknown] | list[Unknown]` may be missing
- paasta_tools/paastaapi/api_client.py:717:21: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown, Unknown] | list[Unknown]` may be missing
+ paasta_tools/paastaapi/api_client.py:713:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ paasta_tools/paastaapi/api_client.py:717:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- paasta_tools/paastaapi/api_client.py:722:21: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown, Unknown] | list[Unknown]` may be missing
- paasta_tools/paastaapi/api_client.py:725:21: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown, Unknown] | list[Unknown]` may be missing
+ paasta_tools/paastaapi/api_client.py:722:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ paasta_tools/paastaapi/api_client.py:725:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- paasta_tools/paastaapi/model_utils.py:169:9: error[invalid-assignment] Cannot assign to object of type `Self@__setattr__` with no `__setitem__` method
+ paasta_tools/paastaapi/model_utils.py:169:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `Self@__setattr__` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:307:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:307:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:311:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:311:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:314:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:314:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:317:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:317:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:318:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:318:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:319:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:319:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:320:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:320:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/setup_kubernetes_cr.py:321:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str] | dict[Unknown, Unknown]` may be missing
+ paasta_tools/setup_kubernetes_cr.py:321:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- paasta_tools/tron/client.py:50:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | dict[Unknown | str, Unknown | str]` may be missing
+ paasta_tools/tron/client.py:50:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method

kopf (https://github.com/nolar/kopf)
- kopf/_cogs/structs/credentials.py:164:25: warning[possibly-missing-implicit-call] Method `__setitem__` of type `dict[str, object] | None` may be missing
+ kopf/_cogs/structs/credentials.py:164:25: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method

pytest (https://github.com/pytest-dev/pytest)
- src/_pytest/pastebin.py:43:13: error[invalid-assignment] Method `__setitem__` of type `Unknown | (bound method Stash.__setitem__[T](key: StashKey[T@__setitem__], value: T@__setitem__) -> None)` cannot be called with a key of type `StashKey[IO[bytes]]` and a value of type `TextIOWrapper[_WrappedBuffer]` on object of type `Unknown | Stash`
+ src/_pytest/pastebin.py:43:13: error[invalid-assignment] Method `__setitem__` of type `bound method Stash.__setitem__[T](key: StashKey[T@__setitem__], value: T@__setitem__) -> None` cannot be called with a key of type `StashKey[IO[bytes]]` and a value of type `TextIOWrapper[_WrappedBuffer]` on object of type `Stash`

sockeye (https://github.com/awslabs/sockeye)
- sockeye/log.py:131:9: error[invalid-assignment] Method `__setitem__` of type `Unknown | (bound method dict[Unknown | str, Unknown | str].__setitem__(key: Unknown | str, value: Unknown | str, /) -> None) | (bound method dict[Unknown | str, Unknown | str | None].__setitem__(key: Unknown | str, value: Unknown | str | None, /) -> None) | (bound method dict[Unknown | str, Unknown | str | int].__setitem__(key: Unknown | str, value: Unknown | str | int, /) -> None) | (Overload[(key: SupportsIndex, value: Unknown | str, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown | str], /) -> None])` cannot be called with a key of type `Literal["level"]` and a value of type `Unknown | Literal[20]` on object of type `Unknown | dict[Unknown | str, Unknown | str] | dict[Unknown | str, Unknown | str | None] | ... omitted 3 union elements`
+ sockeye/log.py:131:9: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown | str, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown | str], /) -> None]` cannot be called with a key of type `Literal["level"]` and a value of type `Unknown | Literal[20]` on object of type `list[Unknown | str]`
+ sockeye/log.py:131:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- Found 406 diagnostics
+ Found 407 diagnostics

pybind11 (https://github.com/pybind/pybind11)
- tests/test_sequences_and_iterators.py:157:5: error[invalid-assignment] Cannot assign to object of type `reversed[Unknown]` with no `__setitem__` method
+ tests/test_sequences_and_iterators.py:157:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `reversed[Unknown]` with no `__setitem__` method

tornado (https://github.com/tornadoweb/tornado)
- tornado/test/httpclient_test.py:521:17: error[invalid-assignment] Method `__setitem__` of type `Unknown | (bound method dict[Unknown, Unknown].__setitem__(key: Unknown, value: Unknown, /) -> None) | (bound method HTTPHeaders.__setitem__(name: str, value: str) -> None)` cannot be called with a key of type `Literal["User-Agent"]` and a value of type `Unknown | str | bytes` on object of type `Unknown | dict[Unknown, Unknown] | HTTPHeaders`
+ tornado/test/httpclient_test.py:521:17: error[invalid-assignment] Method `__setitem__` of type `bound method HTTPHeaders.__setitem__(name: str, value: str) -> None` cannot be called with a key of type `Literal["User-Agent"]` and a value of type `Unknown | str | bytes` on object of type `HTTPHeaders`

poetry (https://github.com/python-poetry/poetry)
+ src/poetry/utils/env/mock_env.py:80:42: warning[unused-ignore-comment] Unused blanket `type: ignore` directive
- Found 975 diagnostics
+ Found 976 diagnostics

urllib3 (https://github.com/urllib3/urllib3)
- src/urllib3/contrib/emscripten/fetch.py:400:9: error[invalid-assignment] Cannot assign to object of type `Buffer` with no `__setitem__` method
+ src/urllib3/contrib/emscripten/fetch.py:400:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `Buffer` with no `__setitem__` method

dragonchain (https://github.com/dragonchain/dragonchain)
- dragonchain/job_processor/contract_job.py:121:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:122:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:127:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:128:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:129:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:130:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:131:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
- dragonchain/job_processor/contract_job.py:132:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None` may be missing
+ dragonchain/job_processor/contract_job.py:121:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:122:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:127:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:128:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:129:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:130:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:131:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ dragonchain/job_processor/contract_job.py:132:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/addons/savehar.py:206:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ mitmproxy/addons/savehar.py:206:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- mitmproxy/addons/savehar.py:206:17: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]) | (bound method dict[Unknown | str, Unknown | int].__setitem__(key: Unknown | str, value: Unknown | int, /) -> None)` cannot be called with a key of type `Literal["text"]` and a value of type `str` on object of type `Unknown | int | str | list[dict[Unknown, Unknown]] | dict[Unknown | str, Unknown | int]`
+ mitmproxy/addons/savehar.py:206:17: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]` cannot be called with a key of type `Literal["text"]` and a value of type `str` on object of type `list[dict[Unknown, Unknown]]`
+ mitmproxy/addons/savehar.py:207:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ mitmproxy/addons/savehar.py:207:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- mitmproxy/addons/savehar.py:207:17: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]) | (bound method dict[Unknown | str, Unknown | int].__setitem__(key: Unknown | str, value: Unknown | int, /) -> None)` cannot be called with a key of type `Literal["encoding"]` and a value of type `Literal["base64"]` on object of type `Unknown | int | str | list[dict[Unknown, Unknown]] | dict[Unknown | str, Unknown | int]`
+ mitmproxy/addons/savehar.py:207:17: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]` cannot be called with a key of type `Literal["encoding"]` and a value of type `Literal["base64"]` on object of type `list[dict[Unknown, Unknown]]`
+ mitmproxy/addons/savehar.py:211:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ mitmproxy/addons/savehar.py:211:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- mitmproxy/addons/savehar.py:211:21: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]) | (bound method dict[Unknown | str, Unknown | int].__setitem__(key: Unknown | str, value: Unknown | int, /) -> None)` cannot be called with a key of type `Literal["text"]` and a value of type `Literal[""]` on object of type `Unknown | int | str | list[dict[Unknown, Unknown]] | dict[Unknown | str, Unknown | int]`
+ mitmproxy/addons/savehar.py:211:21: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]` cannot be called with a key of type `Literal["text"]` and a value of type `Literal[""]` on object of type `list[dict[Unknown, Unknown]]`
+ mitmproxy/addons/savehar.py:213:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ mitmproxy/addons/savehar.py:213:21: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- mitmproxy/addons/savehar.py:213:21: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]) | (bound method dict[Unknown | str, Unknown | int].__setitem__(key: Unknown | str, value: Unknown | int, /) -> None)` cannot be called with a key of type `Literal["text"]` and a value of type `str` on object of type `Unknown | int | str | list[dict[Unknown, Unknown]] | dict[Unknown | str, Unknown | int]`
+ mitmproxy/addons/savehar.py:213:21: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: dict[Unknown, Unknown], /) -> None, (key: slice[Any, Any, Any], value: Iterable[dict[Unknown, Unknown]], /) -> None]` cannot be called with a key of type `Literal["text"]` and a value of type `str` on object of type `list[dict[Unknown, Unknown]]`
- mitmproxy/io/compat.py:324:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | dict[Unknown, Unknown] | str | ... omitted 3 union elements` may be missing
+ mitmproxy/io/compat.py:324:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
+ mitmproxy/io/compat.py:324:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ mitmproxy/io/compat.py:324:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
- Found 1833 diagnostics
+ Found 1843 diagnostics

schema_salad (https://github.com/common-workflow-language/schema_salad)
- schema_salad/jsonld_context.py:211:17: error[invalid-assignment] Method `__setitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None` cannot be called with a key of type `Literal["@id"]` and a value of type `@Todo` on object of type `(CommentedMap & Top[MutableMapping[Unknown, Unknown]]) | (int & Top[MutableMapping[Unknown, Unknown]]) | (float & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]]) | (CommentedSeq & Top[MutableMapping[Unknown, Unknown]])`
+ schema_salad/jsonld_context.py:211:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ schema_salad/jsonld_context.py:211:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `float` with no `__setitem__` method
+ schema_salad/jsonld_context.py:211:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- schema_salad/jsonld_context.py:245:13: error[invalid-assignment] Cannot assign to object of type `object` with no `__setitem__` method
+ schema_salad/jsonld_context.py:245:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `object` with no `__setitem__` method
- schema_salad/jsonld_context.py:252:9: error[invalid-assignment] Method `__setitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None` cannot be called with a key of type `Literal["@context"]` and a value of type `@Todo` on object of type `(CommentedMap & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]]) | (int & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]]) | (float & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]] & ~Top[MutableSequence[Unknown]])`
+ schema_salad/jsonld_context.py:252:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ schema_salad/jsonld_context.py:252:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `float` with no `__setitem__` method
+ schema_salad/jsonld_context.py:252:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- schema_salad/schema.py:541:17: error[invalid-assignment] Method `__setitem__` of type `(bound method MutableMapping[str, Any].__setitem__(key: str, value: Any, /) -> None) | (bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None)` cannot be called with a key of type `Literal["name"]` and a value of type `str` on object of type `MutableMapping[str, Any] | (MutableSequence[Any] & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]])`
- schema_salad/schema.py:543:17: error[invalid-assignment] Method `__setitem__` of type `(bound method MutableMapping[str, Any].__setitem__(key: str, value: Any, /) -> None) | (bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None)` cannot be called with a key of type `Literal["name"]` and a value of type `str` on object of type `MutableMapping[str, Any] | (MutableSequence[Any] & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]])`
+ schema_salad/schema.py:541:17: error[invalid-assignment] Method `__setitem__` of type `Overload[(index: int, value: Any) -> None, (index: slice[Any, Any, Any], value: Iterable[Any]) -> None]` cannot be called with a key of type `Literal["name"]` and a value of type `str` on object of type `MutableSequence[Any]`
+ schema_salad/schema.py:541:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
+ schema_salad/schema.py:543:17: error[invalid-assignment] Method `__setitem__` of type `Overload[(index: int, value: Any) -> None, (index: slice[Any, Any, Any], value: Iterable[Any]) -> None]` cannot be called with a key of type `Literal["name"]` and a value of type `str` on object of type `MutableSequence[Any]`
+ schema_salad/schema.py:543:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- schema_salad/schema.py:563:17: error[invalid-assignment] Method `__setitem__` of type `(bound method MutableMapping[str, Any].__setitem__(key: str, value: Any, /) -> None) | (bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None)` cannot be called with a key of type `Literal["type", "items", "names", "values", "fields"]` and a value of type `MutableMapping[str, Any] | MutableSequence[Any] | str | MutableMapping[str, str] | list[Any | MutableMapping[str, str] | str]` on object of type `MutableMapping[str, Any] | (MutableSequence[Any] & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]])`
- schema_salad/schema.py:572:13: error[invalid-assignment] Method `__setitem__` of type `(bound method MutableMapping[str, Any].__setitem__(key: str, value: Any, /) -> None) | (bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None)` cannot be called with a key of type `Literal["symbols"]` and a value of type `list[str | Unknown]` on object of type `MutableMapping[str, Any] | (MutableSequence[Any] & Top[MutableMapping[Unknown, Unknown]]) | (str & Top[MutableMapping[Unknown, Unknown]])`
+ schema_salad/schema.py:563:17: error[invalid-assignment] Method `__setitem__` of type `Overload[(index: int, value: Any) -> None, (index: slice[Any, Any, Any], value: Iterable[Any]) -> None]` cannot be called with a key of type `Literal["type", "items", "names", "values", "fields"]` and a value of type `MutableMapping[str, Any] | MutableSequence[Any] | str | MutableMapping[str, str] | list[Any | MutableMapping[str, str] | str]` on object of type `MutableSequence[Any]`
+ schema_salad/schema.py:563:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
+ schema_salad/schema.py:572:13: error[invalid-assignment] Method `__setitem__` of type `Overload[(index: int, value: Any) -> None, (index: slice[Any, Any, Any], value: Iterable[Any]) -> None]` cannot be called with a key of type `Literal["symbols"]` and a value of type `list[str | Unknown]` on object of type `MutableSequence[Any]`
+ schema_salad/schema.py:572:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
- Found 176 diagnostics
+ Found 184 diagnostics

mypy (https://github.com/python/mypy)
- mypy/report.py:685:9: error[invalid-assignment] Method `__setitem__` of type `Unknown | (bound method dict[str, Any].__setitem__(key: str, value: Any, /) -> None)` cannot be called with a key of type `bytes` and a value of type `Unknown` on object of type `Unknown | dict[str, Any]`
+ mypy/report.py:685:9: error[invalid-assignment] Method `__setitem__` of type `bound method dict[str, Any].__setitem__(key: str, value: Any, /) -> None` cannot be called with a key of type `bytes` and a value of type `Unknown` on object of type `dict[str, Any]`

psycopg (https://github.com/psycopg/psycopg)
- psycopg/psycopg/_adapters_map.py:147:21: error[invalid-assignment] Method `__setitem__` of type `Unknown | (bound method dict[Unknown, Literal[False]].__setitem__(key: Unknown, value: Literal[False], /) -> None) | (bound method dict[Unknown, Literal[True]].__setitem__(key: Unknown, value: Literal[True], /) -> None)` cannot be called with a key of type `PyFormat` and a value of type `Literal[True]` on object of type `Unknown | dict[Unknown, Literal[False]] | dict[Unknown, Literal[True]]`
+ psycopg/psycopg/_adapters_map.py:147:21: error[invalid-assignment] Method `__setitem__` of type `bound method dict[Unknown, Literal[False]].__setitem__(key: Unknown, value: Literal[False], /) -> None` cannot be called with a key of type `PyFormat` and a value of type `Literal[True]` on object of type `dict[Unknown, Literal[False]]`

Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/clients.py:2720:13: error[invalid-assignment] Method `__setitem__` of type `(bound method dict[str, ModuleType].__setitem__(key: str, value: ModuleType, /) -> None) | (bound method dict[Path, ModuleType].__setitem__(key: Path, value: ModuleType, /) -> None)` cannot be called with a key of type `str | Path` and a value of type `@Todo` on object of type `dict[str, ModuleType] | dict[Path, ModuleType]`
+ tanjun/clients.py:2720:13: error[invalid-assignment] Method `__setitem__` of type `bound method dict[str, ModuleType].__setitem__(key: str, value: ModuleType, /) -> None` cannot be called with a key of type `str | Path` and a value of type `@Todo` on object of type `dict[str, ModuleType]`
+ tanjun/clients.py:2720:13: error[invalid-assignment] Method `__setitem__` of type `bound method dict[Path, ModuleType].__setitem__(key: Path, value: ModuleType, /) -> None` cannot be called with a key of type `str | Path` and a value of type `@Todo` on object of type `dict[Path, ModuleType]`
- Found 153 diagnostics
+ Found 154 diagnostics

freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/freqai/freqai_interface.py:890:21: error[invalid-assignment] Method `__setitem__` of type `Unknown | (bound method dict[str, DataFrame].__setitem__(key: str, value: DataFrame, /) -> None)` cannot be called with a key of type `Unknown | str` and a value of type `Series[Any]` on object of type `Unknown | dict[str, DataFrame]`
+ freqtrade/freqai/freqai_interface.py:890:21: error[invalid-assignment] Method `__setitem__` of type `bound method dict[str, DataFrame].__setitem__(key: str, value: DataFrame, /) -> None` cannot be called with a key of type `Unknown | str` and a value of type `Series[Any]` on object of type `dict[str, DataFrame]`

xarray (https://github.com/pydata/xarray)
- xarray/core/dataset.py:4622:17: error[invalid-assignment] Method `__setitem__` of type `bound method Top[MutableMapping[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None` cannot be called with a key of type `Unknown` and a value of type `int` on object of type `Mapping[Hashable, Any] & Top[MutableMapping[Unknown, Unknown]]`
+ xarray/core/dataset.py:4622:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `Mapping[Hashable, Any]` with no `__setitem__` method
- xarray/core/groupby.py:772:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `DatasetCoordinates | Any | property` may be missing
+ xarray/core/groupby.py:772:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `property` with no `__setitem__` method
- xarray/core/options.py:332:35: error[invalid-key] Invalid key for TypedDict `T_Options` of type `str`
+ xarray/core/options.py:332:35: error[invalid-key] Invalid key of type `str` for TypedDict `T_Options`
- xarray/core/variable.py:1226:17: error[invalid-assignment] Cannot assign to object of type `Mapping[Any, int | float | tuple[int | float, int | float]]` with no `__setitem__` method
+ xarray/core/variable.py:1226:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `Mapping[Any, int | float | tuple[int | float, int | float]]` with no `__setitem__` method
- xarray/groupers.py:637:9: error[invalid-assignment] Cannot assign to object of type `signedinteger[@Todo]` with no `__setitem__` method
+ xarray/groupers.py:637:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `signedinteger[@Todo]` with no `__setitem__` method
- xarray/groupers.py:639:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `signedinteger[@Todo] | @Todo` may be missing
+ xarray/groupers.py:639:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `signedinteger[@Todo]` with no `__setitem__` method

trio (https://github.com/python-trio/trio)
- src/trio/_wait_for_object.py:63:9: error[invalid-assignment] Cannot assign to object of type `HandleArray` with no `__setitem__` method
+ src/trio/_wait_for_object.py:63:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `HandleArray` with no `__setitem__` method

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- pymongo/asynchronous/server.py:275:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | dict[Unknown | str, Unknown | Int64 | str] | int` may be missing
- pymongo/asynchronous/server.py:277:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | dict[Unknown | str, Unknown | Int64 | str] | int` may be missing
+ pymongo/asynchronous/server.py:275:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ pymongo/asynchronous/server.py:277:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
- pymongo/synchronous/server.py:275:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | dict[Unknown | str, Unknown | Int64 | str] | int` may be missing
- pymongo/synchronous/server.py:277:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | dict[Unknown | str, Unknown | Int64 | str] | int` may be missing
+ pymongo/synchronous/server.py:275:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ pymongo/synchronous/server.py:277:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method

discord.py (https://github.com/Rapptz/discord.py)
- discord/gateway.py:466:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | int | dict[Unknown | str, Unknown | str | None | dict[Unknown | str, Unknown | str] | int]` may be missing
- discord/gateway.py:470:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | int | dict[Unknown | str, Unknown | str | None | dict[Unknown | str, Unknown | str] | int]` may be missing
- discord/gateway.py:478:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | int | dict[Unknown | str, Unknown | str | None | dict[Unknown | str, Unknown | str] | int]` may be missing
+ discord/gateway.py:466:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ discord/gateway.py:470:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ discord/gateway.py:478:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
- discord/gateway.py:735:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | int | dict[Unknown | str, Unknown | int]` may be missing
- discord/gateway.py:738:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | int | dict[Unknown | str, Unknown | int]` may be missing
- discord/gateway.py:741:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | int | dict[Unknown | str, Unknown | int]` may be missing
+ discord/gateway.py:735:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ discord/gateway.py:738:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
+ discord/gateway.py:741:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `int` with no `__setitem__` method
- discord/message.py:2404:30: error[invalid-key] Invalid key for TypedDict `Message` of type `str`
+ discord/message.py:2404:30: error[invalid-key] Invalid key of type `str` for TypedDict `Message`

vision (https://github.com/pytorch/vision)
- references/classification/utils.py:319:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `None | Unknown` may be missing
+ references/classification/utils.py:319:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- torchvision/models/densenet.py:235:13: error[invalid-assignment] Cannot assign to object of type `Mapping[str, Any]` with no `__setitem__` method
+ torchvision/models/densenet.py:235:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `Mapping[str, Any]` with no `__setitem__` method
- torchvision/transforms/v2/_utils.py:69:13: error[invalid-assignment] Method `__setitem__` of type `(bound method Top[dict[Unknown, Unknown]].__setitem__(key: Never, value: Never, /) -> None) | (bound method dict[type | str, int | float | Sequence[int | float] | None].__setitem__(key: type | str, value: int | float | Sequence[int | float] | None, /) -> None)` cannot be called with a key of type `object` and a value of type `list[int | float] | None` on object of type `(Sequence[int | float] & Top[dict[Unknown, Unknown]]) | dict[type | str, int | float | Sequence[int | float] | None]`
+ torchvision/transforms/v2/_utils.py:69:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `Sequence[int | float]` with no `__setitem__` method
+ torchvision/transforms/v2/_utils.py:69:13: error[invalid-assignment] Method `__setitem__` of type `bound method dict[type | str, int | float | Sequence[int | float] | None].__setitem__(key: type | str, value: int | float | Sequence[int | float] | None, /) -> None` cannot be called with a key of type `object` and a value of type `list[int | float] | None` on object of type `dict[type | str, int | float | Sequence[int | float] | None]`
- Found 1445 diagnostics
+ Found 1446 diagnostics

pyppeteer (https://github.com/pyppeteer/pyppeteer)
- pyppeteer/network_manager.py:727:13: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | str | None | dict[Unknown, Unknown]` may be missing
+ pyppeteer/network_manager.py:727:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `str` with no `__setitem__` method
+ pyppeteer/network_manager.py:727:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- Found 87 diagnostics
+ Found 88 diagnostics

cloud-init (https://github.com/canonical/cloud-init)
- cloudinit/cmd/main.py:952:5: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown | str, Unknown | list[Unknown] | dict[Unknown, Unknown] | None]` may be missing
+ cloudinit/cmd/main.py:952:5: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- cloudinit/cmd/main.py:995:9: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | None | dict[Unknown | str, Unknown | list[Unknown] | dict[Unknown, Unknown] | None]` may be missing
+ cloudinit/cmd/main.py:995:9: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
+ cloudinit/cmd/main.py:1003:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- cloudinit/cmd/main.py:1003:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | list[Unknown] | dict[Unknown, Unknown] | None` may be missing
+ cloudinit/cmd/main.py:1010:17: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- cloudinit/cmd/main.py:1010:17: warning[possibly-missing-implicit-call] Method `__setitem__` of type `Unknown | list[Unknown] | dict[Unknown, Unknown] | None` may be missing
- cloudinit/net/network_state.py:340:17: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["dns"]` and a value of type `dict[Unknown | str, Unknown]` on object of type `(Unknown & ~AlwaysFalsy) | (list[Unknown] & ~AlwaysFalsy)`
+ cloudinit/net/network_state.py:340:17: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]` cannot be called with a key of type `Literal["dns"]` and a value of type `dict[Unknown | str, Unknown]` on object of type `list[Unknown]`
- cloudinit/net/network_state.py:437:13: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["mac_address"]` and a value of type `Unknown` on object of type `Unknown | list[Unknown]`
+ cloudinit/net/network_state.py:437:13: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]` cannot be called with a key of type `Literal["mac_address"]` and a value of type `Unknown` on object of type `list[Unknown]`
- cloudinit/net/network_state.py:456:9: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["vlan-raw-device"]` and a value of type `Unknown` on object of type `Unknown | list[Unknown]`
+ cloudinit/net/network_state.py:456:9: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]` cannot be called with a key of type `Literal["vlan-raw-device"]` and a value of type `Unknown` on object of type `list[Unknown]`
- cloudinit/net/network_state.py:457:9: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["vlan_id"]` and a value of type `Unknown` on object of type `Unknown | list[Unknown]`
+ cloudinit/net/network_state.py:457:9: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]` cannot be called with a key of type `Literal["vlan_id"]` and a value of type `Unknown` on object of type `list[Unknown]`
+ cloudinit/net/network_state.py:507:13: error[invalid-assignment] Cannot assign to a subscript on an object of type `None` with no `__setitem__` method
- cloudinit/net/network_state.py:507:13: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["bond-master"]` and a value of type `Unknown` on object of type `Unknown | None | list[Unknown]`
+ cloudinit/net/network_state.py:507:13: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]` cannot be called with a key of type `Literal["bond-master"]` and a value of type `Unknown` on object of type `list[Unknown]`
- cloudinit/net/network_state.py:558:9: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["bridge_ports"]` and a value of type `Unknown` on object of type `Unknown | list[Unknown]`
+ cloudinit/net/network_state.py:558:9: error[invalid-assignment] Method `__setitem__` of type `Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None]` cannot be called with a key of type `Literal["bridge_ports"]` and a value of type `Unknown` on object of type `list[Unknown]`
- cloudinit/net/network_state.py:616:9: error[invalid-assignment] Method `__setitem__` of type `Unknown | (Overload[(key: SupportsIndex, value: Unknown, /) -> None, (key: slice[Any, Any, Any], value: Iterable[Unknown], /) -> None])` cannot be called with a key of type `Literal["dns"]` and a value of type `dict[Unknown | str, Unknown]

... (truncated 3104 lines) ...
Memory usage changes were detected when running on open source projects
flake8 (https://github.com/pycqa/flake8)
- TOTAL MEMORY USAGE: ~66MB
+ TOTAL MEMORY USAGE: ~63MB

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 11, 2025

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-key 1,907 0 122
invalid-assignment 504 49 183
possibly-missing-implicit-call 0 272 0
unused-ignore-comment 3 0 0
Total 2,414 321 305

Full report with detailed diff (timing results)

@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch 2 times, most recently from bd4e1b7 to 634597c Compare November 11, 2025 13:35
@sharkdp sharkdp marked this pull request as ready for review November 11, 2025 13:45
@AlexWaygood
Copy link
Member

I wondered about how this might affect assignability and subtyping of TypedDicts to protocols, e.g.

from ty_extensions import static_assert, is_subtype_of, is_assignable_to
from typing import Protocol, Literal, TypedDict

class Foo(Protocol):
    def __setitem__(self, key: Literal["x"], value: int, /) -> None: ...

class Bar(TypedDict):
    x: int

static_assert(is_assignable_to(Bar, Foo))
static_assert(is_subtype_of(Bar, Foo))

but I suppose it's impossible to test that right now, because TypedDicts are currently considered assignable to everything and subtypes of nothing, until astral-sh/ty#1387 is fixed?

@AlexWaygood
Copy link
Member

If need be, we could always add a special case for TypedDict -> Protocol assignability/subtyping (we could synthesize the required method on the fly during the assignability/subtyping check?), but it's nice to keep that kind of special case to a minimum.

@sharkdp

This comment was marked as resolved.

@AlexWaygood

This comment was marked as resolved.

@sharkdp

This comment was marked as resolved.

@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch from 37b32b2 to 8653a6d Compare November 12, 2025 12:35
@sharkdp sharkdp changed the title [ty] Faster subscript assignment checks on TypedDicts [ty] Faster subscript assignment checks for (unions of) TypedDicts Nov 12, 2025
@sharkdp sharkdp marked this pull request as draft November 12, 2025 12:37
@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch from 8653a6d to 0c65dc6 Compare November 12, 2025 12:50
@astral-sh-bot

This comment was marked as resolved.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 12, 2025

CodSpeed Performance Report

Merging #21378 will improve performances by 86.14%

Comparing david/faster-subscript-assignment-checks (ccb7a0c) with main (84c3cec)

Summary

⚡ 1 improvement
✅ 51 untouched
⏩ 2 skipped1

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
WallTime large[pydantic] 38.2 s 20.5 s +86.14%

Footnotes

  1. 2 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.

@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch from 0c65dc6 to c17b16e Compare November 12, 2025 14:30
@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch from c17b16e to 5cce18c Compare November 12, 2025 14:55
@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch from 5cce18c to 306e619 Compare November 12, 2025 15:23
@sharkdp sharkdp force-pushed the david/faster-subscript-assignment-checks branch from 306e619 to ccb7a0c Compare November 12, 2025 15:44
@sharkdp sharkdp marked this pull request as ready for review November 12, 2025 16:02
Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Awesome work. None of my comments below are blocking, just thoughts that occurred to me as I read through the diff

Comment on lines +33 to +43
Copy link
Member

Choose a reason for hiding this comment

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

What about including the name of the unknown key in the summary line here and taking it out of the primary-annotation message?

error[invalid-key]: Invalid key "surname" for TypedDict `Person`
  --> src/mdtest_snippet.py:13:5
   |
11 |     # error: [invalid-key]
12 |     # error: [invalid-key]
13 |     being["surname"] = "unknown"
   |     ----- ^^^^^^^^^ Did you mean "name"?
   |     |
   |     TypedDict `Person` in union type `Person | Animal`
   |
info: rule `invalid-key` is enabled by default

We could also consider linking back to the definition of the Person typeddict in a subdiagnostic, though I guess that would be very verbose if you had a union of typeddicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about including the name of the unknown key in the summary line here and taking it out of the primary-annotation message?

I can try that, but it's always a bit tricky to get both the full diagnostic and the concise diagnostic to look good. I still wish we had an API to set a separate concise message.

@@ -143,30 +143,57 @@ impl TypedDictAssignmentKind {
pub(super) fn validate_typed_dict_key_assignment<'db, 'ast>(
Copy link
Member

Choose a reason for hiding this comment

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

Calls to this function are becoming quite difficult to read because of how many arguments there are. Especially the third argument, where None is often passed, and the last argument which is a bool. We could consider refactoring this into a struct that holds all the options for better readability, e.g.

let validator = TypedDictValidator {
    context: &self.context,
    typed_dict,
    full_object_ty: None,
    key,
    value_ty,
    typed_dict_node,
    key_node,
    value_node,
    assignment_kind,
    emit_diagnostics: true
};

validator.validate();

@sharkdp sharkdp merged commit 2f6f3e1 into main Nov 12, 2025
42 of 44 checks passed
@sharkdp sharkdp deleted the david/faster-subscript-assignment-checks branch November 12, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ecosystem-analyzer performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments