Skip to content

[match-case] fix matching against typing.Callable and Protocol types. #19471

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

randolf-scholz
Copy link
Contributor

(Explain how this PR changes mypy.)

I added an extra if-branch that checks for typing.Callable in visit_class_pattern, and an extra if-branch to handle structural types in the conditional_types function.

Copy link
Contributor

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

strawberry (https://github.com/strawberry-graphql/strawberry)
+ strawberry/relay/types.py:849: error: Need type annotation for "v"  [var-annotated]
+ strawberry/relay/types.py:849: note: Error code "var-annotated" not covered by "type: ignore" comment
+ strawberry/relay/types.py:854: error: Argument 1 to "enumerate" has incompatible type "AsyncIterator[NodeType] | AsyncIterable[NodeType]"; expected "Iterable[Never]"  [arg-type]

prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/flows.py:1239: error: Argument 1 to "BlockStorageAdapter" has incompatible type "Union[ReadableDeploymentStorage, RunnerStorage]"; expected "Union[ReadableDeploymentStorage, WritableDeploymentStorage]"  [arg-type]
+ src/prefect/flows.py:1353: error: Argument 1 to "BlockStorageAdapter" has incompatible type "Union[ReadableDeploymentStorage, RunnerStorage]"; expected "Union[ReadableDeploymentStorage, WritableDeploymentStorage]"  [arg-type]
+ src/prefect/tasks.py:945: error: Incompatible return value type (got "Coroutine[Any, Any, TaskRun]", expected "TaskRun")  [return-value]
+ src/prefect/tasks.py:945: note: Maybe you forgot to use "await"?

meson (https://github.com/mesonbuild/meson)
+ mesonbuild/compilers/mixins/clike.py:411:29: error: List item 0 has incompatible type "list[Dependency]"; expected "Dependency"  [list-item]

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:607: error: Unused "type: ignore" comment  [unused-ignore]

xarray (https://github.com/pydata/xarray)
+ xarray/core/dataset.py: note: In member "drop_vars" of class "Dataset":
+ xarray/core/dataset.py:5796: error: Argument 1 to "set" has incompatible type "Iterable[Hashable]"; expected "Iterable[Iterable[Hashable]]"  [arg-type]
+ xarray/core/dataset.py:5798: error: Argument 1 to "_assert_all_in_dataset" of "Dataset" has incompatible type "set[Iterable[Hashable]]"; expected "Iterable[Hashable]"  [arg-type]
+ xarray/core/dataset.py:5803: error: No overload variant of "get" of "dict" matches argument types "Iterable[Hashable]", "None"  [call-overload]
+ xarray/core/dataset.py:5803: note: Possible overload variants:
+ xarray/core/dataset.py:5803: note:     def get(self, Hashable, None = ..., /) -> Index | None
+ xarray/core/dataset.py:5803: note:     def get(self, Hashable, Index, /) -> Index
+ xarray/core/dataset.py:5803: note:     def [_T] get(self, Hashable, _T, /) -> Index | _T
+ xarray/core/dataset.py:5806: error: Argument 1 to "set" has incompatible type "set[Iterable[Hashable]]"; expected "Iterable[Hashable]"  [arg-type]
+ xarray/core/dataset.py:5809: error: Argument 1 to "set" has incompatible type "set[Hashable]"; expected "Iterable[Iterable[Hashable]]"  [arg-type]
+ xarray/core/dataset.py:5816: error: Argument 2 to "assert_no_index_corrupted" has incompatible type "set[Iterable[Hashable]]"; expected "set[Hashable]"  [arg-type]
+ xarray/core/dataset.py: note: In member "drop_dims" of class "Dataset":
+ xarray/core/dataset.py:6102: error: Argument 1 to <set> has incompatible type "str | Iterable[Hashable]"; expected "Hashable"  [arg-type]
+ xarray/core/dataset.py: note: At top level:
+ xarray/core/datatree.py: note: In member "drop_nodes" of class "DataTree":
+ xarray/core/datatree.py:1133: error: Argument 1 to <set> has incompatible type "str | Iterable[str]"; expected "str"  [arg-type]
+ xarray/backends/api.py: note: In function "to_netcdf":
+ xarray/backends/api.py:1973: error: List item 0 has incompatible type "Iterable[Hashable]"; expected "Hashable"  [list-item]
+ xarray/backends/api.py: note: At top level:
+ xarray/computation/fit.py: note: In function "curvefit":
+ xarray/computation/fit.py:407: error: List item 0 has incompatible type "str | DataArray | Iterable[str | DataArray]"; expected "str | DataArray"  [list-item]

graphql-core (https://github.com/graphql-python/graphql-core)
+ tests/execution/test_subscribe.py:292: error: Unused "type: ignore" comment  [unused-ignore]

websockets (https://github.com/aaugustin/websockets)
+ src/websockets/legacy/server.py:368: error: Incompatible return value type (got "Awaitable[tuple[HTTPStatus | int, Headers | Mapping[str, str] | Iterable[tuple[str, str]] | SupportsKeysAndGetItem, bytes] | None]", expected "tuple[HTTPStatus | int, Headers | Mapping[str, str] | Iterable[tuple[str, str]] | SupportsKeysAndGetItem, bytes] | None")  [return-value]
+ src/websockets/legacy/server.py:368: note: Maybe you forgot to use "await"?
+ src/websockets/legacy/server.py:591: error: Incompatible types in assignment (expression has type "Coroutine[Any, Any, tuple[HTTPStatus | int, Headers | Mapping[str, str] | Iterable[tuple[str, str]] | SupportsKeysAndGetItem, bytes] | None]", variable has type "tuple[HTTPStatus | int, Headers | Mapping[str, str] | Iterable[tuple[str, str]] | SupportsKeysAndGetItem, bytes] | None")  [assignment]
+ src/websockets/legacy/server.py:591: note: Maybe you forgot to use "await"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant