-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Try assuming covariance during inference #17468
base: master
Are you sure you want to change the base?
Conversation
Diff from mypy_primer, showing the effect of this PR on open source code: aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
tests/test_runserver_serve.py:42: error: Unused "type: ignore" comment [unused-ignore]
tests/test_runserver_serve.py:42: error: Invalid index type "AppKey[set[tuple[WebSocketResponse, str]]]" for "Application"; expected type "AppKey[object]" [index]
tests/test_runserver_serve.py:42: note: Error code "index" not covered by "type: ignore" comment
tests/test_runserver_serve.py:63: error: Unused "type: ignore" comment [unused-ignore]
tests/test_runserver_serve.py:63: error: Invalid index type "AppKey[set[tuple[WebSocketResponse, str]]]" for "Application"; expected type "AppKey[object]" [index]
tests/test_runserver_serve.py:63: note: Error code "index" not covered by "type: ignore" comment
tests/test_runserver_serve.py:82: error: Unused "type: ignore" comment [unused-ignore]
tests/test_runserver_serve.py:82: error: Invalid index type "AppKey[set[tuple[WebSocketResponse, str]]]" for "Application"; expected type "AppKey[object]" [index]
tests/test_runserver_serve.py:82: note: Error code "index" not covered by "type: ignore" comment
tests/test_runserver_serve.py:95: error: Unused "type: ignore" comment [unused-ignore]
tests/test_runserver_serve.py:95: error: Invalid index type "AppKey[set[tuple[WebSocketResponse, str]]]" for "Application"; expected type "AppKey[object]" [index]
tests/test_runserver_serve.py:95: note: Error code "index" not covered by "type: ignore" comment
tests/test_runserver_serve.py:106: error: Unused "type: ignore" comment [unused-ignore]
tests/test_runserver_serve.py:106: error: Invalid index type "AppKey[set[tuple[WebSocketResponse, str]]]" for "Application"; expected type "AppKey[object]" [index]
tests/test_runserver_serve.py:106: note: Error code "index" not covered by "type: ignore" comment
tests/test_runserver_watch.py:92: error: Unused "type: ignore" comment [unused-ignore]
tests/test_runserver_watch.py:92: error: Invalid index type "AppKey[set[tuple[WebSocketResponse, str]]]" for "Application"; expected type "AppKey[object]" [index]
tests/test_runserver_watch.py:92: note: Error code "index" not covered by "type: ignore" comment
core (https://github.com/home-assistant/core)
homeassistant/util/hass_dict.pyi:123: error: Unused "type: ignore" comment [unused-ignore]
homeassistant/util/hass_dict.pyi:123: error: Invalid index type "HassKey[int]" for "HassDict"; expected type "HassKey[object]" [index]
homeassistant/util/hass_dict.pyi:123: note: Error code "index" not covered by "type: ignore" comment
homeassistant/util/hass_dict.pyi:124: error: Unused "type: ignore" comment [unused-ignore]
homeassistant/util/hass_dict.pyi:124: error: Invalid index type "HassKey[int]" for "HassDict"; expected type "HassKey[object]" [index]
homeassistant/util/hass_dict.pyi:124: note: Error code "index" not covered by "type: ignore" comment
homeassistant/util/hass_dict.pyi:126: error: Unused "type: ignore" comment [unused-ignore]
homeassistant/util/hass_dict.pyi:126: error: Invalid index type "HassKey[dict[int, bool]]" for "HassDict"; expected type "HassKey[object]" [index]
homeassistant/util/hass_dict.pyi:126: note: Error code "index" not covered by "type: ignore" comment
homeassistant/util/hass_dict.pyi:128: error: Unused "type: ignore" comment [unused-ignore]
homeassistant/util/hass_dict.pyi:128: error: Invalid index type "HassKey[set[str]]" for "HassDict"; expected type "HassKey[object]" [index]
homeassistant/util/hass_dict.pyi:128: note: Error code "index" not covered by "type: ignore" comment
homeassistant/util/hass_dict.pyi:157: error: Unused "type: ignore" comment [unused-ignore]
homeassistant/util/hass_dict.pyi:157: error: Argument 1 to "setdefault" of "HassDict" has incompatible type "HassKey[int]"; expected "HassKey[object]" [arg-type]
homeassistant/util/hass_dict.pyi:157: note: Error code "arg-type" not covered by "type: ignore" comment
homeassistant/core.py:2285: error: Unused "type: ignore" comment [unused-ignore]
homeassistant/core.py:2286: error: Argument 1 to "async_fire_internal" of "EventBus" has incompatible type "EventType[EventStateReportedData]"; expected "EventType[Mapping[str, object | Any]] | str" [arg-type]
homeassistant/components/roborock/__init__.py:45: error: Incompatible return value type (got "list[RoborockDataUpdateCoordinator]", expected "list[RoborockDataUpdateCoordinator | RoborockDataUpdateCoordinatorA01]") [return-value]
homeassistant/components/roborock/__init__.py:45: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
homeassistant/components/roborock/__init__.py:45: note: Consider using "Sequence" instead, which is covariant
homeassistant/components/roborock/__init__.py:45: error: Unsupported operand types for ("list[RoborockDataUpdateCoordinator]" and "list[RoborockDataUpdateCoordinatorA01]") [operator]
prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/utilities/callables.py:564: error: Incompatible types in assignment (expression has type "list[None]", variable has type "list[expr | None]") [assignment]
- src/prefect/utilities/callables.py:564: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
- src/prefect/utilities/callables.py:564: note: Consider using "Sequence" instead, which is covariant
- src/prefect/utilities/callables.py:566: error: Unsupported operand types for ("list[None]" and "list[expr | None]") [operator]
materialize (https://github.com/MaterializeInc/materialize)
misc/python/materialize/parallel_workload/database.py:951: error: Incompatible return value type (got "list[PostgresSource | MySqlSource | KafkaSource | View | Table]", expected "list[WebhookSource | MySqlSource | PostgresSource | KafkaSource | View | Table]") [return-value]
misc/python/materialize/parallel_workload/database.py:951: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
misc/python/materialize/parallel_workload/database.py:951: note: Consider using "Sequence" instead, which is covariant
misc/python/materialize/parallel_workload/database.py:956: error: Unsupported operand types for ("list[PostgresSource | MySqlSource | KafkaSource | View | Table]" and "list[WebhookSource]") [operator]
streamlit (https://github.com/streamlit/streamlit)
- lib/tests/streamlit/elements/element_utils_test.py:87:16: error: Cannot infer type argument 1 of "maybe_coerce_enum_sequence" [misc]
- lib/tests/streamlit/elements/element_utils_test.py:90:13: error: Cannot infer type argument 1 of "maybe_coerce_enum_sequence" [misc]
lib/tests/streamlit/elements/element_utils_test.py:87:43: error: Argument 1 to "maybe_coerce_enum_sequence" has incompatible type "RegisterWidgetResult[List[EnumA]]"; expected "RegisterWidgetResult[List[object]]" [arg-type]
lib/tests/streamlit/elements/element_utils_test.py:90:40: error: Argument 1 to "maybe_coerce_enum_sequence" has incompatible type "RegisterWidgetResult[List[int]]"; expected "RegisterWidgetResult[List[object]]" [arg-type]
pydantic (https://github.com/pydantic/pydantic)
- pydantic/aliases.py:28: error: Incompatible types in assignment (expression has type "list[str]", variable has type "list[int | str]") [assignment]
- pydantic/aliases.py:28: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
- pydantic/aliases.py:28: note: Consider using "Sequence" instead, which is covariant
- pydantic/aliases.py:28: error: Argument 1 to "list" has incompatible type "tuple[str | int, ...]"; expected "Iterable[str]" [arg-type]
|
TBH I don't really like the |
Interesting! The changes in mypy primer output are smaller than I was expecting. I'll look at them in more detail later. This probably isn't useful right now, but if we change type inference to prefer unions, this might become more interesting. Once we have an experiment that avoids the use of joins for type inference, we could try it also with this, and see if the results look better. |
No description provided.