Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for bidirectional type inference for assignment stateme… #9705

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

erictraut
Copy link
Collaborator

…nts that are assigning to an index expression that is subscripted by a slice. This addresses #9564.

…nts that are assigning to an index expression that is subscripted by a slice. This addresses #9564.
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

sympy (https://github.com/sympy/sympy)
-   /tmp/mypy_primer/projects/sympy/sympy/integrals/intpoly.py:748:17 - error: Argument of type "list[Unknown]" cannot be assigned to parameter "value" of type "None" in function "__setitem__"
+   /tmp/mypy_primer/projects/sympy/sympy/integrals/intpoly.py:748:17 - error: Argument of type "list[Any | int]" cannot be assigned to parameter "value" of type "None" in function "__setitem__"
-     "list[Unknown]" is not assignable to "None" (reportArgumentType)
+     "list[Any | int]" is not assignable to "None" (reportArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/physics/control/lti.py:2066:23 - error: Operator "-" not supported for type "Basic" (reportOperatorIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/physics/control/lti.py:2066:23 - error: Operator "-" not supported for type "Basic" when expected type is "Basic" (reportOperatorIssue)
-     Operator "**" not supported for types "Basic" and "Basic"
+     Operator "**" not supported for types "Basic" and "Basic" when expected type is "Expr"
-     Operator "**" not supported for types "Dict" and "Basic" (reportOperatorIssue)
+     Operator "**" not supported for types "Dict" and "Basic" when expected type is "Expr" (reportOperatorIssue)
-   /tmp/mypy_primer/projects/sympy/sympy/tensor/tensor.py:3858:27 - error: Operator "-" not supported for type "Basic" (reportOperatorIssue)
+   /tmp/mypy_primer/projects/sympy/sympy/tensor/tensor.py:3858:27 - error: Operator "-" not supported for type "Basic" when expected type is "Basic" (reportOperatorIssue)

core (https://github.com/home-assistant/core)
+   /tmp/mypy_primer/projects/core/homeassistant/loader.py:270:5 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/loader.py:270:5 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, ModuleType | ComponentProtocol]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, ModuleType | ComponentProtocol]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "ModuleType | ComponentProtocol"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/loader.py:271:5 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/loader.py:271:5 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, Integration | Future[None]]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, Integration | Future[None]]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "Integration | Future[None]"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/loader.py:272:5 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/loader.py:272:5 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, bool]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, bool]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "bool"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/setup.py:108:18 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/setup.py:108:18 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, str | None]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, str | None]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "str | None"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/setup.py:110:5 - error: Argument of type "object* | str | None" cannot be assigned to parameter "value" of type "str | None" in function "__setitem__"
+     Type "object* | str | None" is not assignable to type "str | None"
+       Type "object*" is not assignable to type "str | None"
+         "object*" is not assignable to "str"
+         "object*" is not assignable to "None" (reportArgumentType)
+ /tmp/mypy_primer/projects/core/homeassistant/components/arwn/sensor.py
+   /tmp/mypy_primer/projects/core/homeassistant/components/arwn/sensor.py:147:17 - error: Argument of type "() -> (str | UndefinedType | None)" cannot be assigned to parameter "key" of type "str" in function "__setitem__"
+     "function" is not assignable to "str" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/arwn/sensor.py:158:17 - error: Argument of type "() -> (str | UndefinedType | None)" cannot be assigned to parameter "key" of type "str" in function "__getitem__"
+     "function" is not assignable to "str" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/arwn/sensor.py:158:36 - error: Cannot access attribute "set_event" for class "object*"
+     Attribute "set_event" is unknown (reportAttributeAccessIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/assist_satellite/__init__.py:66:5 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/assist_satellite/__init__.py:66:5 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, Event]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, Event]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "Event"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/profiler/__init__.py:120:9 - error: Object of type "object*" is not callable
+     Attribute "__call__" is unknown (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/profiler/__init__.py:163:9 - error: Object of type "object*" is not callable
+     Attribute "__call__" is unknown (reportCallIssue)
+ /tmp/mypy_primer/projects/core/homeassistant/components/stt/legacy.py
+   /tmp/mypy_primer/projects/core/homeassistant/components/stt/legacy.py:59:17 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/stt/legacy.py:59:17 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, Provider]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, Provider]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "Provider"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/components/trace/__init__.py:50:5 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/components/trace/__init__.py:50:5 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "TraceData"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, LimitedSizeDict[str, BaseTrace]]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "LimitedSizeDict[str, BaseTrace]"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+ /tmp/mypy_primer/projects/core/homeassistant/components/websocket_api/__init__.py
+   /tmp/mypy_primer/projects/core/homeassistant/components/websocket_api/__init__.py:67:5 - error: Argument of type "Any | str | WebSocketCommandHandler" cannot be assigned to parameter "key" of type "str" in function "__setitem__"
+     Type "Any | str | WebSocketCommandHandler" is not assignable to type "str"
+       "function" is not assignable to "str" (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/helpers/llm.py:631:32 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/helpers/llm.py:631:32 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, tuple[str | None, Unknown]]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, tuple[str | None, Unknown]]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "tuple[str | None, Unknown]"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/helpers/llm.py:654:20 - error: Type "_S@__setitem__ | tuple[str | None, Unknown]" is not assignable to return type "tuple[str | None, Unknown]"
+     Type "object* | tuple[str | None, Unknown]" is not assignable to type "tuple[str | None, Unknown]"
+       "object*" is not assignable to "tuple[str | None, Unknown]" (reportReturnType)
+   /tmp/mypy_primer/projects/core/homeassistant/helpers/script.py:1433:13 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)
+   /tmp/mypy_primer/projects/core/homeassistant/helpers/script.py:1433:13 - error: Argument of type "dict[str, _S@__setitem__]" cannot be assigned to parameter "value" of type "_S@__setitem__" in function "__setitem__"
+     Type "dict[str, _S@__setitem__]" is not assignable to type "dict[str, dict[str, set[str]]]"
+       "dict[str, _S@__setitem__]" is not assignable to "dict[str, dict[str, set[str]]]"
+         Type parameter "_VT@dict" is invariant, but "_S@__setitem__" is not the same as "dict[str, set[str]]"
+         Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
+   /tmp/mypy_primer/projects/core/homeassistant/helpers/script.py:2059:5 - error: No overloads for "__setitem__" match the provided arguments (reportCallIssue)

... (truncated 36 lines) ...

pycryptodome (https://github.com/Legrandin/pycryptodome)
-   /tmp/mypy_primer/projects/pycryptodome/lib/Crypto/SelfTest/Hash/test_TupleHash.py:262:13 - error: Argument of type "list[Unknown]" cannot be assigned to parameter "value" of type "None" in function "__setitem__"
+   /tmp/mypy_primer/projects/pycryptodome/lib/Crypto/SelfTest/Hash/test_TupleHash.py:262:13 - error: Argument of type "list[Any]" cannot be assigned to parameter "value" of type "None" in function "__setitem__"
-     "list[Unknown]" is not assignable to "None" (reportArgumentType)
+     "list[Any]" is not assignable to "None" (reportArgumentType)

@erictraut erictraut merged commit c1edc0b into main Jan 14, 2025
18 checks passed
@erictraut erictraut deleted the issue-9564 branch January 14, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant