mypy
mypy copied to clipboard
Keep `TypeVar` arguments when narrowing generic subclasses with `isinstance` and `issubclass`.
Fixes #16933
@finite-state-machine When I first read your issue, I thought only a special case was left unconsidered. However, I then realized that Mypy's narrowing of generic classes often tends to insert Any
for type variables and so silently reduces type safety. I put some effort into handling all relevant cases I could think of (including variadic generics, which is new to me), but it is likely I missed some. Would you like to have a look at it?
Diff from mypy_primer, showing the effect of this PR on open source code:
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:593: error: Generator has incompatible item type "tuple[None, bytes]"; expected "tuple[bytes, bytes]" [misc]
+ mitmproxy/http.py:594: error: Argument 1 to "always_bytes" has incompatible type "str | bytes | Any | tuple[bytes, bytes]"; expected "None" [arg-type]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/filters.py:166: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[str, Any] | dict_items[tuple[str, Any], Any]", variable has type "Iterable[tuple[str, Any]]") [assignment]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/date/array.py:105: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:106: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:107: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "iteritems":
+ bidict/_iter.py:25:9: error: Incompatible types in "yield from" (actual type "tuple[Any, Any] | tuple[tuple[KT, VT], Any]", expected type "tuple[KT, VT]") [misc]
antidote (https://github.com/Finistere/antidote)
+ src/antidote/lib/interface_ext/_interface.py:531: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
+ /tmp/mypy_primer/projects/_prefect_venv/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py:1750: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.10.0+dev.3731abb84cbc77595e44ce12afc55b8936551acd
+ note: use --pdb to drop into pdb
- src/prefect/utilities/processutils.py:226: error: Name "_windows_process_group_pids" is not defined [name-defined]
- src/prefect/server/events/schemas/labelling.py:74: error: Unexpected keyword argument "extra" for "__init_subclass__" of "object" [call-arg]
- note: "__init_subclass__" of "object" defined here
- src/prefect/_internal/concurrency/event_loop.py:23: error: Incompatible return value type (got "AbstractEventLoop", expected "BaseEventLoop | None") [return-value]
- src/prefect/_internal/concurrency/event_loop.py:61: error: Need type annotation for "future" [var-annotated]
- src/prefect/software/pip.py:62: error: Argument 1 to "_is_same_path" has incompatible type "SimplePath"; expected "Path | str" [arg-type]
- src/prefect/software/pip.py:63: error: Argument 1 to "_is_child_path" has incompatible type "SimplePath"; expected "Path | str" [arg-type]
- src/prefect/_internal/concurrency/primitives.py:29: error: Need type annotation for "_waiters" [var-annotated]
- src/prefect/_vendor/starlette/responses.py:44: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/requests.py:161: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/routing.py:864: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/routing.py:878: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/routing.py:892: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/routing.py:906: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/routing.py:922: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/routing.py:929: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:358: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:359: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:377: error: Incompatible default for argument "headers" (default has type "None", argument has type "dict[str, str]") [assignment]
- src/prefect/_vendor/starlette/testclient.py:377: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- src/prefect/_vendor/starlette/testclient.py:377: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- src/prefect/_vendor/starlette/testclient.py:442: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:482: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:511: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:540: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:569: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:606: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:643: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:680: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/testclient.py:710: error: Incompatible default for argument "subprotocols" (default has type "None", argument has type "Sequence[str]") [assignment]
- src/prefect/_vendor/starlette/testclient.py:710: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- src/prefect/_vendor/starlette/testclient.py:710: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- src/prefect/_vendor/starlette/templating.py:21: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/templating.py:23: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/staticfiles.py:113: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/responses.py:20: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/responses.py:26: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/security/api_key.py:24: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/security/api_key.py:53: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/security/api_key.py:82: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:125: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:149: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:175: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:182: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:194: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:208: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:220: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:234: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:240: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/starlette/applications.py:257: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/dependencies/utils.py:402: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/routing.py:440: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/_vendor/fastapi/openapi/utils.py:336: error: Argument 2 to "deep_dict_update" has incompatible type "dict[str, Any] | None"; expected "dict[Any, Any]" [arg-type]
- src/prefect/_vendor/fastapi/openapi/utils.py:485: error: Unused "type: ignore" comment [unused-ignore]
- src/prefect/server/utilities/subscriptions.py:19: error: Function does not return a value (it only ever returns None) [func-returns-value]
- src/prefect/server/utilities/subscriptions.py:33: error: Function does not return a value (it only ever returns None) [func-returns-value]
- src/prefect/server/utilities/server.py:24: error: Item "None" of "set[str] | None" has no attribute "__iter__" (not iterable) [union-attr]
- src/prefect/server/utilities/server.py:78: error: "Callable[[VarArg(Any), NamedArg(Request, 'request'), KwArg(Any)], Coroutine[Any, Any, Any]]" has no attribute "__signature__" [attr-defined]
- src/prefect/server/utilities/database.py:443: error: Incompatible types in assignment (expression has type "type[BOOLEAN]", base class "ColumnElement" defined the type as "TypeEngine[Any]") [assignment]
- src/prefect/server/utilities/database.py:514: error: Incompatible types in assignment (expression has type "type[BOOLEAN]", base class "ColumnElement" defined the type as "TypeEngine[Any]") [assignment]
- src/prefect/server/utilities/database.py:569: error: Incompatible types in assignment (expression has type "type[BOOLEAN]", base class "ColumnElement" defined the type as "TypeEngine[Any]") [assignment]
- src/prefect/server/utilities/database.py:632: error: Item "Connection" of "Engine | Connection | None" has no attribute "url" [union-attr]
- src/prefect/server/utilities/database.py:632: error: Item "None" of "Engine | Connection | None" has no attribute "url" [union-attr]
- src/prefect/server/utilities/database.py:638: error: Incompatible return value type (got "type[Dialect] | Any", expected "Dialect") [return-value]
- src/prefect/client/utilities.py:75: error: Incompatible types in assignment (expression has type "_AsyncGeneratorContextManager[Any]", variable has type "PrefectClient") [assignment]
- src/prefect/utilities/templating.py:170: error: Incompatible default for argument "client" (default has type "None", argument has type "PrefectClient") [assignment]
- src/prefect/utilities/templating.py:170: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- src/prefect/utilities/templating.py:170: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- src/prefect/utilities/templating.py:285: error: Name "value_keypath" already defined on line 267 [no-redef]
- src/prefect/utilities/templating.py:304: error: Incompatible default for argument "client" (default has type "None", argument has type "PrefectClient") [assignment]
- src/prefect/utilities/templating.py:304: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
- src/prefect/utilities/templating.py:304: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
- src/prefect/_internal/concurrency/cancellation.py:69: error: Incompatible types in assignment (expression has type "Exception", variable has type "None") [assignment]
- src/prefect/_internal/concurrency/cancellation.py:75: error: "_RLock" has no attribute "_count" [attr-defined]
... (truncated 3045 lines) ...
mypy (https://github.com/python/mypy)
+ mypy/types.py:3582: error: Redundant cast to "List[Type]" [redundant-cast]
+ mypy/types.py:3582: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:206: error: Incompatible return value type (got "Any | Exception", expected "ResponseError") [return-value]
optuna (https://github.com/optuna/optuna)
+ /tmp/mypy_primer/projects/_optuna_venv/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py:1750: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.10.0+dev.3731abb84cbc77595e44ce12afc55b8936551acd
+ note: use --pdb to drop into pdb
- optuna/_gp/acqf.py:149: error: Unused "type: ignore" comment [unused-ignore]
- optuna/_gp/acqf.py:150: error: Unused "type: ignore" comment [unused-ignore]
- tests/gp_tests/test_acqf.py:59: error: Unused "type: ignore" comment [unused-ignore]
- optuna/testing/storages.py:65: error: Unused "type: ignore" comment [unused-ignore]
- optuna/importance/_ped_anova/scott_parzen_estimator.py:109: error: Unused "type: ignore" comment [unused-ignore]
- optuna/importance/_ped_anova/scott_parzen_estimator.py:110: error: Unused "type: ignore" comment [unused-ignore]
- tests/storages_tests/test_journal.py:57: error: Unused "type: ignore" comment [unused-ignore]
- tests/samplers_tests/test_nsgaii.py:968: error: Unused "type: ignore" comment [unused-ignore]
- tests/samplers_tests/test_grid.py:43: error: Unused "type: ignore" comment [unused-ignore]
- tests/samplers_tests/test_grid.py:51: error: Unused "type: ignore" comment [unused-ignore]
- tests/samplers_tests/test_grid.py:57: error: Unused "type: ignore" comment [unused-ignore]
- tests/samplers_tests/test_grid.py:69: error: Unused "type: ignore" comment [unused-ignore]
- tests/samplers_tests/test_grid.py:123: error: Unused "type: ignore" comment [unused-ignore]
- tests/artifacts_tests/test_boto3.py:17: error: Unused "type: ignore[attr-defined, no-redef]" comment [unused-ignore]
+ Traceback (most recent call last):
+ File "", line 8, in <module>
+ sys.exit(console_entry())
+ File "/__main__.py", line 15, in console_entry
+ main()
+ File "/main.py", line 100, in main
+ res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+ File "/main.py", line 182, in run_build
+ res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+ File "/build.py", line 192, in build
+ result = _build(
+ File "/build.py", line 266, in _build
+ graph = dispatch(sources, manager, stdout)
+ File "/build.py", line 2942, in dispatch
+ process_graph(graph, manager)
+ File "/build.py", line 3340, in process_graph
+ process_stale_scc(graph, scc, manager)
+ File "/build.py", line 3441, in process_stale_scc
+ graph[id].type_check_first_pass()
+ File "/build.py", line 2310, in type_check_first_pass
+ self.type_checker().check_first_pass()
+ File "/checker.py", line 481, in check_first_pass
+ self.accept(d)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1142, in accept
+ return visitor.visit_class_def(self)
+ File "/checker.py", line 2333, in visit_class_def
+ self.accept(defn.defs)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1223, in accept
+ return visitor.visit_block(self)
+ File "/checker.py", line 2795, in visit_block
+ self.accept(s)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 787, in accept
+ return visitor.visit_func_def(self)
+ File "/checker.py", line 1000, in visit_func_def
+ self._visit_func_def(defn)
+ File "/checker.py", line 1004, in _visit_func_def
+ self.check_func_item(defn, name=defn.name)
+ File "/checker.py", line 1077, in check_func_item
+ self.check_func_def(defn, typ, name, allow_empty)
+ File "/checker.py", line 1309, in check_func_def
+ self.accept(item.body)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1223, in accept
+ return visitor.visit_block(self)
+ File "/checker.py", line 2795, in visit_block
+ self.accept(s)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1491, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4547, in visit_if_stmt
+ if_map, else_map = self.find_isinstance_check(e)
+ File "/checker.py", line 5693, in find_isinstance_check
+ if_map, else_map = self.find_isinstance_check_helper(node)
+ File "/checker.py", line 6002, in find_isinstance_check_helper
+ left, right = self.find_isinstance_check(node.expr)
+ File "/checker.py", line 5693, in find_isinstance_check
+ if_map, else_map = self.find_isinstance_check_helper(node)
+ File "/checker.py", line 5712, in find_isinstance_check_helper
+ *self.conditional_types_with_intersection(
+ File "/checker.py", line 7170, in conditional_types_with_intersection
+ initial_types = conditional_types(expr_type, type_ranges, default)
+ File "/checker.py", line 7474, in conditional_types
+ proposed_type_with_data = _transfer_type_var_args_from_current_to_proposed(
+ File "/checker.py", line 7584, in _transfer_type_var_args_from_current_to_proposed
+ if pos2 is not None:
+ UnboundLocalError: local variable 'pos2' referenced before assignment
pandas-stubs (https://github.com/pandas-dev/pandas-stubs)
+ /tmp/mypy_primer/projects/_pandas-stubs_venv/lib/python3.10/site-packages/sqlalchemy/sql/type_api.py:1750: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
+ https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
+ Please report a bug at https://github.com/python/mypy/issues
+ version: 1.10.0+dev.3731abb84cbc77595e44ce12afc55b8936551acd
+ note: use --pdb to drop into pdb
+ Traceback (most recent call last):
+ File "", line 8, in <module>
+ sys.exit(console_entry())
+ File "/__main__.py", line 15, in console_entry
+ main()
+ File "/main.py", line 100, in main
+ res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
+ File "/main.py", line 182, in run_build
+ res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
+ File "/build.py", line 192, in build
+ result = _build(
+ File "/build.py", line 266, in _build
+ graph = dispatch(sources, manager, stdout)
+ File "/build.py", line 2942, in dispatch
+ process_graph(graph, manager)
+ File "/build.py", line 3340, in process_graph
+ process_stale_scc(graph, scc, manager)
+ File "/build.py", line 3441, in process_stale_scc
+ graph[id].type_check_first_pass()
+ File "/build.py", line 2310, in type_check_first_pass
+ self.type_checker().check_first_pass()
+ File "/checker.py", line 481, in check_first_pass
+ self.accept(d)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1142, in accept
+ return visitor.visit_class_def(self)
+ File "/checker.py", line 2333, in visit_class_def
+ self.accept(defn.defs)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1223, in accept
+ return visitor.visit_block(self)
+ File "/checker.py", line 2795, in visit_block
+ self.accept(s)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 787, in accept
+ return visitor.visit_func_def(self)
+ File "/checker.py", line 1000, in visit_func_def
+ self._visit_func_def(defn)
+ File "/checker.py", line 1004, in _visit_func_def
+ self.check_func_item(defn, name=defn.name)
+ File "/checker.py", line 1077, in check_func_item
+ self.check_func_def(defn, typ, name, allow_empty)
+ File "/checker.py", line 1309, in check_func_def
+ self.accept(item.body)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1223, in accept
+ return visitor.visit_block(self)
+ File "/checker.py", line 2795, in visit_block
+ self.accept(s)
+ File "/checker.py", line 589, in accept
+ stmt.accept(self)
+ File "/nodes.py", line 1491, in accept
+ return visitor.visit_if_stmt(self)
+ File "/checker.py", line 4547, in visit_if_stmt
+ if_map, else_map = self.find_isinstance_check(e)
+ File "/checker.py", line 5693, in find_isinstance_check
+ if_map, else_map = self.find_isinstance_check_helper(node)
+ File "/checker.py", line 6002, in find_isinstance_check_helper
+ left, right = self.find_isinstance_check(node.expr)
+ File "/checker.py", line 5693, in find_isinstance_check
+ if_map, else_map = self.find_isinstance_check_helper(node)
+ File "/checker.py", line 5712, in find_isinstance_check_helper
+ *self.conditional_types_with_intersection(
+ File "/checker.py", line 7170, in conditional_types_with_intersection
+ initial_types = conditional_types(expr_type, type_ranges, default)
+ File "/checker.py", line 7474, in conditional_types
+ proposed_type_with_data = _transfer_type_var_args_from_current_to_proposed(
+ File "/checker.py", line 7584, in _transfer_type_var_args_from_current_to_proposed
+ if pos2 is not None:
+ UnboundLocalError: local variable 'pos2' referenced before assignment
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/helpers.py:123: error: Argument 1 to "append" of "list" has incompatible type "tuple[str, int | str | Mapping[str, Any]]"; expected "tuple[str, int]" [arg-type]
+ pymongo/cursor.py:798: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
+ pymongo/cursor.py:820: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
jax (https://github.com/google/jax)
- jax/_src/interpreters/xla.py:95: error: Unused "type: ignore" comment [unused-ignore]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/reactor/subhandling.py:70: error: Argument "id" to "generate_id" has incompatible type "Callable[[NamedArg(int, 'retry'), NamedArg(datetime, 'started'), NamedArg(timedelta, 'runtime'), NamedArg(Mapping[str, str], 'annotations'), NamedArg(Mapping[str, str], 'labels'), NamedArg(Body, 'body'), NamedArg(Meta, 'meta'), NamedArg(Spec, 'spec'), NamedArg(Status, 'status'), NamedArg(Resource, 'resource'), NamedArg(str | None, 'uid'), NamedArg(str | None, 'name'), NamedArg(str | None, 'namespace'), NamedArg(Patch, 'patch'), NamedArg(str, 'reason'), NamedArg(Diff, 'diff'), NamedArg(BodyEssence | Any | None, 'old'), NamedArg(BodyEssence | Any | None, 'new'), NamedArg(Logger | LoggerAdapter[Any], 'logger'), NamedArg(Any, 'memo'), DefaultNamedArg(Any, 'param'), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"; expected "str | None" [arg-type]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/process.py: note: In function "relocateOutputs":
+ cwltool/process.py:330:51: error: Argument 1 to "_collectDirEntries" has incompatible type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected "CWLObjectType | MutableSequence[CWLObjectType] | None" [arg-type]
+ tests/test_examples.py: note: In function "test_factory_partial_scatter":
+ tests/test_examples.py:327:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:327:12: note: Possible overload variants:
+ tests/test_examples.py:327:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:327:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:327:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:327:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:328:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:328:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:329:12: note: Possible overload variants:
+ tests/test_examples.py:329:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:329:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:329:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_factory_partial_output":
+ tests/test_examples.py:342:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:342:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:342:12: note: Possible overload variants:
+ tests/test_examples.py:342:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:342:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:342:27: error: Invalid index type "str" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_scatter_output_filenames":
+ tests/test_examples.py:1639:21: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" [type-var]
+ tests/test_examples.py:1639:28: error: Value of type "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:1639:28: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:1639:28: note: Possible overload variants:
+ tests/test_examples.py:1639:28: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:1639:28: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:1639:36: error: Invalid index type "str" for "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:1639:63: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1642:13: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
... (truncated 206 lines) ...```
Diff from mypy_primer, showing the effect of this PR on open source code:
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:593: error: Generator has incompatible item type "tuple[None, bytes]"; expected "tuple[bytes, bytes]" [misc]
+ mitmproxy/http.py:594: error: Argument 1 to "always_bytes" has incompatible type "str | bytes | Any | tuple[bytes, bytes]"; expected "None" [arg-type]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/filters.py:166: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[str, Any] | dict_items[tuple[str, Any], Any]", variable has type "Iterable[tuple[str, Any]]") [assignment]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/date/array.py:105: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:106: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:107: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "iteritems":
+ bidict/_iter.py:25:9: error: Incompatible types in "yield from" (actual type "tuple[Any, Any] | tuple[tuple[KT, VT], Any]", expected type "tuple[KT, VT]") [misc]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/cli/cloud/__init__.py:197: error: Incompatible types in assignment (expression has type "Hashable", variable has type "Sequence[Hashable]") [assignment]
antidote (https://github.com/Finistere/antidote)
+ src/antidote/lib/interface_ext/_interface.py:531: error: Unused "type: ignore" comment [unused-ignore]
mypy (https://github.com/python/mypy)
+ mypy/types.py:3582: error: Redundant cast to "List[Type]" [redundant-cast]
+ mypy/types.py:3582: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:206: error: Incompatible return value type (got "Any | Exception", expected "ResponseError") [return-value]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/process.py: note: In function "relocateOutputs":
+ cwltool/process.py:330:51: error: Argument 1 to "_collectDirEntries" has incompatible type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected "CWLObjectType | MutableSequence[CWLObjectType] | None" [arg-type]
+ tests/test_examples.py: note: In function "test_factory_partial_scatter":
+ tests/test_examples.py:327:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:327:12: note: Possible overload variants:
+ tests/test_examples.py:327:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:327:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:327:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:327:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:328:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:328:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:329:12: note: Possible overload variants:
+ tests/test_examples.py:329:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:329:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:329:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_factory_partial_output":
+ tests/test_examples.py:342:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:342:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:342:12: note: Possible overload variants:
+ tests/test_examples.py:342:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:342:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:342:27: error: Invalid index type "str" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_scatter_output_filenames":
+ tests/test_examples.py:1639:21: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" [type-var]
+ tests/test_examples.py:1639:28: error: Value of type "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:1639:28: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:1639:28: note: Possible overload variants:
+ tests/test_examples.py:1639:28: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:1639:28: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:1639:36: error: Invalid index type "str" for "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:1639:63: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1642:13: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/helpers.py:123: error: Argument 1 to "append" of "list" has incompatible type "tuple[str, int | str | Mapping[str, Any]]"; expected "tuple[str, int]" [arg-type]
+ pymongo/cursor.py:798: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
+ pymongo/cursor.py:820: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
spark (https://github.com/apache/spark)
+ python/pyspark/ml/linalg/__init__.py:603: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[tuple[int, float], Any] | dict_items[int, float]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/sql/connect/expressions.py:941: error: Argument 1 to "join" of "str" has incompatible type "list[UnresolvedNamedLambdaVariable]"; expected "Iterable[str]" [arg-type]
+ python/pyspark/mllib/linalg/__init__.py:661: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[tuple[int, float], Any] | dict_items[int, float]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/ml/functions.py:288: error: Incompatible types in assignment (expression has type "list[Any]", target has type "ndarray[Any, Any]") [assignment]
jax (https://github.com/google/jax)
- jax/_src/interpreters/xla.py:95: error: Unused "type: ignore" comment [unused-ignore]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/reactor/subhandling.py:70: error: Argument "id" to "generate_id" has incompatible type "Callable[[NamedArg(int, 'retry'), NamedArg(datetime, 'started'), NamedArg(timedelta, 'runtime'), NamedArg(Mapping[str, str], 'annotations'), NamedArg(Mapping[str, str], 'labels'), NamedArg(Body, 'body'), NamedArg(Meta, 'meta'), NamedArg(Spec, 'spec'), NamedArg(Status, 'status'), NamedArg(Resource, 'resource'), NamedArg(str | None, 'uid'), NamedArg(str | None, 'name'), NamedArg(str | None, 'namespace'), NamedArg(Patch, 'patch'), NamedArg(str, 'reason'), NamedArg(Diff, 'diff'), NamedArg(BodyEssence | Any | None, 'old'), NamedArg(BodyEssence | Any | None, 'new'), NamedArg(Logger | LoggerAdapter[Any], 'logger'), NamedArg(Any, 'memo'), DefaultNamedArg(Any, 'param'), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"; expected "str | None" [arg-type]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/cookiejar.py:178:23: error: Incompatible types in assignment (expression has type "ItemsView[str, str | BaseCookie[str] | Morsel[Any]] | ItemsView[Any, Any] | ItemsView[tuple[str, str | BaseCookie[str] | Morsel[Any]], Any] | dict_items[str, Morsel[str]]", variable has type "Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str]") [assignment]
+ aiohttp/cookiejar.py:180:9: error: Unpacking a string is disallowed [misc]
+ aiohttp/client_reqrep.py:412:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:412:19: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-index for more info
+ aiohttp/client_reqrep.py:414:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:414:19: note: Error code "index" not covered by "type: ignore" comment
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/elements/widgets/time_widgets.py: note: In function "_parse_date_value":
+ lib/streamlit/elements/widgets/time_widgets.py:94:25: error: List comprehension has incompatible type List[Union[date, None, Any]]; expected List[date] [misc]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[Any, Any] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[Any, Any] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/utils/datatypes.py:97: error: Unpacking a string is disallowed [misc]
+ scrapy/utils/datatypes.py:97: error: Value of type variable "AnyStr" of "normkey" of "CaselessDict" cannot be "int | bytes" [type-var]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[Any, Any] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[Any, Any] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/http/headers.py:48: error: Unpacking a string is disallowed [misc]
+ scrapy/http/headers.py:49: error: Value of type variable "AnyStr" of "normkey" of "Headers" cannot be "int | bytes" [type-var]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_collections.py:352: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "str") [assignment]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:131: error: Incompatible return value type (got "tuple[Any, ...] | tuple[V, ...]", expected "tuple[V]") [return-value]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/middleware/shared_data.py:120: error: Incompatible types in assignment (expression has type "Union[dict_items[str, Union[str, Tuple[str, str]]], dict_items[Any, Any], dict_items[Tuple[str, Union[str, Tuple[str, str]]], Any]]", variable has type "Union[Dict[str, Union[str, Tuple[str, str]]], Iterable[Tuple[str, Union[str, Tuple[str, str]]]]]") [assignment]
+ src/werkzeug/middleware/shared_data.py:122: error: Unpacking a string is disallowed [misc]
Went through some of these examples:
-
mitmproxy
: True positive??. The problem is that adict[K, V] | Iterable[tuple[K, V]]
is being checked againstdict
, resulting indict[K, V] | dict[tuple[K, V], Any]
. I guess such a dict would be valid, but that's really not the intent of this code obviously. I think this needs type negation to be safely expressed. -
jinja
: Same asmitmproxy
. -
pandas
: True positive.Sequence[date] | tuple[ndarray, ndarray, ndarray]
with an instance check oftuple
succeeds with both not just the tuple. Here they could swap tolist
I think? -
bidict
: Same asmitmproxy
except withMapping
. -
prefect
: False positive, but looks like an existing join vs union issue? The inferred result forenumerate(list[str] | list[tuple[Hashable, str]])
isenumerate[Sequence[Hashable]]
. -
antidote
: A now-redundantcast()
call. -
mypy
: A now-redundantcast()
call. -
aioredis
: This is a true positive, the dict values should be constrained to only byResponseError
not any exception. This repo is archived though, should probably remove it? -
urllib3
: Same iterable/mapping overlap. -
ibis
: True positive, the return type is wrong I think. -
werkzeug
: Same iterable/dict issue, then a unpack-string error following on from the wrong inference.
Something does seem to need to be done about the mapping/iterable overlap, it seems a lot of projects have very similar code which will be basically untypable right now in a subtle way. Would a special case make sense, or maybe a rule about refusing to narrow if some of the typevars are underermined in that union element?
@tyralla and @TeamSpen210: thank you so much for your work on this!
While I'm reasonably handy when it comes to using mypy, I have very little knowledge of its internals; I don't think I'm the right person to look over a patch.
(I would like to get comfortable with mypy's internals and start fixing bugs rather than just reporting them, but I'm not really sure where to start.)
(I would like to get comfortable with mypy's internals and start fixing bugs rather than just reporting them, but I'm not really sure where to start.)
I think few of us are really comfortable with mypy's internals. I would start simply by reading a PR like this, trying to understand the new code and reading related code, and that hopefully will eventually expand to a broader knowledge of how mypy works.
Something does seem to need to be done about the mapping/iterable overlap, it seems a lot of projects have very similar code which will be basically untypable right now in a subtle way. Would a special case make sense, or maybe a rule about refusing to narrow if some of the typevars are underermined in that union element?
Thank you for this very comprehensive analysis, @TeamSpen210. Given the amount of Mypy primer output, I'm happy that we seem to face only one problematic case. (I agree that the false positive for prefect
is likely related to the joins issue but not this PR.)
I applied Pyright, Pyre (both on their playgrounds with the respective default settings), and Mypy (including the proposed changes) to this simplified mapping/iterable example:
from typing import Iterable
def f(x: dict[str, str] | Iterable[bytes]) -> None:
if isinstance(x, dict):
reveal_type(x)
- Pyright: Type of "x" is "dict[str, str] | dict[bytes, Unknown]"
-
Pyre: Revealed type [-1]: Revealed type for
x
istyping.Dict[str, str]
. - Mypy: Revealed type is "Union[builtins.dict[builtins.str, builtins.str], builtins.dict[Any, Any], builtins.dict[builtins.bytes, Any]]"
So, Pyright and (changed) Mypy behave identically, except for the unnecessary dict[Any, Any]
returned by Mypy. I will check if this has to do with the proposed changes.
On the other hand, Pyre only narrows to dict[str, str]
. At first sight, this is due to Pyre only transferring type variable arguments if such a transfer would be complete. At least the following example leaves this impression:
def f(x: Iterable[bytes]) -> None:
if isinstance(x, dict):
reveal_type(x) # Revealed type [-1]: Revealed type for `x` is `typing.Dict[typing.Any, typing.Any]`. (Pyre)
Personally, I would favour the Pyright-like approach. Adding an option for switching between Pyright's and Pyre's behaviour could also be an option. I also checked the typing specs' narrowing section, but this topic is not covered. Do you think it should, @JelleZijlstra?
Diff from mypy_primer, showing the effect of this PR on open source code:
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:593: error: Generator has incompatible item type "tuple[None, bytes]"; expected "tuple[bytes, bytes]" [misc]
+ mitmproxy/http.py:594: error: Argument 1 to "always_bytes" has incompatible type "str | bytes | Any | tuple[bytes, bytes]"; expected "None" [arg-type]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/filters.py:166: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[str, Any] | dict_items[tuple[str, Any], Any]", variable has type "Iterable[tuple[str, Any]]") [assignment]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/date/array.py:105: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:106: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:107: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "iteritems":
+ bidict/_iter.py:25:9: error: Incompatible types in "yield from" (actual type "tuple[Any, Any] | tuple[tuple[KT, VT], Any]", expected type "tuple[KT, VT]") [misc]
antidote (https://github.com/Finistere/antidote)
+ src/antidote/lib/interface_ext/_interface.py:531: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/cli/cloud/__init__.py:197: error: Incompatible types in assignment (expression has type "Hashable", variable has type "Sequence[Hashable]") [assignment]
mypy (https://github.com/python/mypy)
+ mypy/types.py:3582: error: Redundant cast to "List[Type]" [redundant-cast]
+ mypy/types.py:3582: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:206: error: Incompatible return value type (got "Any | Exception", expected "ResponseError") [return-value]
spark (https://github.com/apache/spark)
+ python/pyspark/ml/linalg/__init__.py:603: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/sql/connect/expressions.py:941: error: Argument 1 to "join" of "str" has incompatible type "list[UnresolvedNamedLambdaVariable]"; expected "Iterable[str]" [arg-type]
+ python/pyspark/mllib/linalg/__init__.py:661: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/ml/functions.py:288: error: Incompatible types in assignment (expression has type "list[Any]", target has type "ndarray[Any, Any]") [assignment]
+ python/pyspark/pandas/frame.py:7435: error: Unsupported operand types for < ("tuple[Any, ...]" and "int") [operator]
+ python/pyspark/pandas/frame.py:7435: note: Left operand is of type "int | Any | tuple[Any, ...]"
+ python/pyspark/pandas/frame.py:7443: error: No overload variant of "__add__" of "tuple" matches argument type "int" [operator]
+ python/pyspark/pandas/frame.py:7443: note: Possible overload variants:
+ python/pyspark/pandas/frame.py:7443: note: def __add__(self, tuple[Any, ...], /) -> tuple[Any, ...]
+ python/pyspark/pandas/frame.py:7443: note: def [_T] __add__(self, tuple[_T, ...], /) -> tuple[Any | _T, ...]
+ python/pyspark/pandas/frame.py:7443: note: Left operand is of type "int | Any | tuple[Any, ...]"
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/process.py: note: In function "relocateOutputs":
+ cwltool/process.py:330:51: error: Argument 1 to "_collectDirEntries" has incompatible type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected "CWLObjectType | MutableSequence[CWLObjectType] | None" [arg-type]
+ tests/test_examples.py: note: In function "test_factory_partial_scatter":
+ tests/test_examples.py:327:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:327:12: note: Possible overload variants:
+ tests/test_examples.py:327:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:327:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:327:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:327:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:328:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:328:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:329:12: note: Possible overload variants:
+ tests/test_examples.py:329:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:329:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:329:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_factory_partial_output":
+ tests/test_examples.py:342:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:342:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:342:12: note: Possible overload variants:
+ tests/test_examples.py:342:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:342:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:342:27: error: Invalid index type "str" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_scatter_output_filenames":
+ tests/test_examples.py:1639:21: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" [type-var]
+ tests/test_examples.py:1639:28: error: Value of type "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:1639:28: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:1639:28: note: Possible overload variants:
+ tests/test_examples.py:1639:28: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:1639:28: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:1639:36: error: Invalid index type "str" for "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:1639:63: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1642:13: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/helpers.py:123: error: Argument 1 to "append" of "list" has incompatible type "tuple[str, int | str | Mapping[str, Any]]"; expected "tuple[str, int]" [arg-type]
+ pymongo/cursor.py:798: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
+ pymongo/cursor.py:820: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/reactor/subhandling.py:70: error: Argument "id" to "generate_id" has incompatible type "Callable[[NamedArg(int, 'retry'), NamedArg(datetime, 'started'), NamedArg(timedelta, 'runtime'), NamedArg(Mapping[str, str], 'annotations'), NamedArg(Mapping[str, str], 'labels'), NamedArg(Body, 'body'), NamedArg(Meta, 'meta'), NamedArg(Spec, 'spec'), NamedArg(Status, 'status'), NamedArg(Resource, 'resource'), NamedArg(str | None, 'uid'), NamedArg(str | None, 'name'), NamedArg(str | None, 'namespace'), NamedArg(Patch, 'patch'), NamedArg(str, 'reason'), NamedArg(Diff, 'diff'), NamedArg(BodyEssence | Any | None, 'old'), NamedArg(BodyEssence | Any | None, 'new'), NamedArg(Logger | LoggerAdapter[Any], 'logger'), NamedArg(Any, 'memo'), DefaultNamedArg(Any, 'param'), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"; expected "str | None" [arg-type]
jax (https://github.com/google/jax)
- jax/_src/interpreters/xla.py:95: error: Unused "type: ignore" comment [unused-ignore]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/cookiejar.py:178:23: error: Incompatible types in assignment (expression has type "ItemsView[str, str | BaseCookie[str] | Morsel[Any]] | ItemsView[tuple[str, str | BaseCookie[str] | Morsel[Any]], Any] | ItemsView[Any, Any] | dict_items[str, Morsel[str]]", variable has type "Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str]") [assignment]
+ aiohttp/cookiejar.py:180:9: error: Unpacking a string is disallowed [misc]
+ aiohttp/client_reqrep.py:412:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:412:19: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-index for more info
+ aiohttp/client_reqrep.py:414:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:414:19: note: Error code "index" not covered by "type: ignore" comment
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_collections.py:352: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "str") [assignment]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/middleware/shared_data.py:120: error: Incompatible types in assignment (expression has type "Union[dict_items[str, Union[str, Tuple[str, str]]], dict_items[Tuple[str, Union[str, Tuple[str, str]]], Any]]", variable has type "Union[Dict[str, Union[str, Tuple[str, str]]], Iterable[Tuple[str, Union[str, Tuple[str, str]]]]]") [assignment]
+ src/werkzeug/middleware/shared_data.py:122: error: Unpacking a string is disallowed [misc]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/elements/widgets/time_widgets.py: note: In function "_parse_date_value":
+ lib/streamlit/elements/widgets/time_widgets.py:94:25: error: List comprehension has incompatible type List[Union[date, None, Any]]; expected List[date] [misc]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/utils/datatypes.py:97: error: Unpacking a string is disallowed [misc]
+ scrapy/utils/datatypes.py:97: error: Value of type variable "AnyStr" of "normkey" of "CaselessDict" cannot be "int | bytes" [type-var]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/http/headers.py:48: error: Unpacking a string is disallowed [misc]
+ scrapy/http/headers.py:49: error: Value of type variable "AnyStr" of "normkey" of "Headers" cannot be "int | bytes" [type-var]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:131: error: Incompatible return value type (got "tuple[Any, ...] | tuple[V, ...]", expected "tuple[V]") [return-value]
Diff from mypy_primer, showing the effect of this PR on open source code:
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:593: error: Generator has incompatible item type "tuple[None, bytes]"; expected "tuple[bytes, bytes]" [misc]
+ mitmproxy/http.py:594: error: Argument 1 to "always_bytes" has incompatible type "str | bytes | Any | tuple[bytes, bytes]"; expected "None" [arg-type]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/filters.py:166: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[str, Any] | dict_items[tuple[str, Any], Any]", variable has type "Iterable[tuple[str, Any]]") [assignment]
schema_salad (https://github.com/common-workflow-language/schema_salad)
+ schema_salad/ref_resolver.py: note: In member "_resolve_uris" of class "Loader":
+ schema_salad/ref_resolver.py:824:21: error: Need type annotation for "url" [var-annotated]
+ schema_salad/ref_resolver.py:826:29: error: Unsupported target for indexed assignment (Never) [index]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/date/array.py:105: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:106: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:107: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "iteritems":
+ bidict/_iter.py:25:9: error: Incompatible types in "yield from" (actual type "tuple[Any, Any] | tuple[tuple[KT, VT], Any]", expected type "tuple[KT, VT]") [misc]
antidote (https://github.com/Finistere/antidote)
+ src/antidote/lib/interface_ext/_interface.py:531: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/cli/cloud/__init__.py:197: error: Incompatible types in assignment (expression has type "Hashable", variable has type "Sequence[Hashable]") [assignment]
mypy (https://github.com/python/mypy)
+ mypy/types.py:3582: error: Redundant cast to "List[Type]" [redundant-cast]
+ mypy/types.py:3582: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info
koda-validate (https://github.com/keithasaurus/koda-validate)
+ koda_validate/serialization/json_schema.py:434: error: Unsupported target for indexed assignment (Never) [index]
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:206: error: Incompatible return value type (got "Any | Exception", expected "ResponseError") [return-value]
+ aioredis/client.py:2715: error: Never has no attribute "items" [attr-defined]
+ aioredis/client.py:2970: error: Never has no attribute "items" [attr-defined]
+ aioredis/client.py:3011: error: Never has no attribute "keys" [attr-defined]
+ aioredis/client.py:3012: error: Never has no attribute "values" [attr-defined]
vision (https://github.com/pytorch/vision)
+ torchvision/transforms/v2/_misc.py:259: error: Invalid index type "str" for "dict[Any, Any] | dict[type[Any], str] | dict[type[Any] | str, Any] | Any"; expected type "type[Any]" [index]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/reactor/subhandling.py:70: error: Argument "id" to "generate_id" has incompatible type "Callable[[NamedArg(int, 'retry'), NamedArg(datetime, 'started'), NamedArg(timedelta, 'runtime'), NamedArg(Mapping[str, str], 'annotations'), NamedArg(Mapping[str, str], 'labels'), NamedArg(Body, 'body'), NamedArg(Meta, 'meta'), NamedArg(Spec, 'spec'), NamedArg(Status, 'status'), NamedArg(Resource, 'resource'), NamedArg(str | None, 'uid'), NamedArg(str | None, 'name'), NamedArg(str | None, 'namespace'), NamedArg(Patch, 'patch'), NamedArg(str, 'reason'), NamedArg(Diff, 'diff'), NamedArg(BodyEssence | Any | None, 'old'), NamedArg(BodyEssence | Any | None, 'new'), NamedArg(Logger | LoggerAdapter[Any], 'logger'), NamedArg(Any, 'memo'), DefaultNamedArg(Any, 'param'), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"; expected "str | None" [arg-type]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/helpers.py:122: error: Incompatible types in assignment (expression has type "tuple[str, int]", variable has type "str") [assignment]
+ pymongo/helpers.py:123: error: Argument 1 to "append" of "list" has incompatible type "str"; expected "tuple[str, int]" [arg-type]
+ pymongo/cursor.py:798: error: Argument 1 to "dict" has incompatible type "list[str, tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str, ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
+ pymongo/cursor.py:820: error: Argument 1 to "dict" has incompatible type "list[str, tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str, ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/update.py: note: In function "v1_0to1_1":
+ cwltool/update.py:63:24: error: Never has no attribute "__iter__" (not iterable) [attr-defined]
+ cwltool/update.py:67:37: error: Value of type Never is not indexable [index]
+ cwltool/update.py:69:25: error: Unsupported target for indexed assignment (Never) [index]
+ cwltool/process.py: note: In function "avroize_type":
+ cwltool/process.py:448:29: error: Incompatible types in assignment (expression has type "CWLObjectType | MutableSequence[Any] | str | int | float | MutableSequence[CWLOutputType] | None", target has type "None") [assignment]
+ cwltool/load_tool.py: note: In function "fetch_document":
+ cwltool/load_tool.py:146:25: error: Value of type Never is not indexable [index]
+ cwltool/load_tool.py:146:48: error: Never has no attribute "get" [attr-defined]
+ cwltool/command_line_tool.py: note: In member "updatePathmap" of class "CommandLineTool":
+ cwltool/command_line_tool.py:491:30: error: Value of type Never is not indexable [index]
+ cwltool/command_line_tool.py:492:12: error: Never has no attribute "__iter__" (not iterable) [attr-defined]
+ cwltool/command_line_tool.py:493:34: error: Value of type Never is not indexable [index]
+ cwltool/command_line_tool.py:499:36: error: Never has no attribute "get" [attr-defined]
+ cwltool/command_line_tool.py:499:76: error: Value of type Never is not indexable [index]
+ cwltool/command_line_tool.py:502:45: error: Never has no attribute "get" [attr-defined]
+ cwltool/command_line_tool.py:504:45: error: Never has no attribute "get" [attr-defined]
+ cwltool/command_line_tool.py:505:63: error: Value of type Never is not indexable [index]
spark (https://github.com/apache/spark)
+ python/pyspark/ml/linalg/__init__.py:603: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/sql/connect/expressions.py:941: error: Argument 1 to "join" of "str" has incompatible type "list[UnresolvedNamedLambdaVariable]"; expected "Iterable[str]" [arg-type]
+ python/pyspark/mllib/linalg/__init__.py:661: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/sql/connect/window.py:93: error: Never has no attribute "__iter__" (not iterable) [attr-defined]
+ python/pyspark/sql/connect/window.py:126: error: Never has no attribute "__iter__" (not iterable) [attr-defined]
+ python/pyspark/ml/functions.py:288: error: Incompatible types in assignment (expression has type "list[Any]", target has type "ndarray[Any, Any]") [assignment]
+ python/pyspark/sql/connect/group.py:247: error: Never has no attribute "__iter__" (not iterable) [attr-defined]
+ python/pyspark/pandas/frame.py:6788: error: Never has no attribute "items" [attr-defined]
+ python/pyspark/pandas/groupby.py:286: error: Never has no attribute "items" [attr-defined]
PyGithub (https://github.com/PyGithub/PyGithub)
+ github/GithubObject.py:331: error: Never has no attribute "items" [attr-defined]
+ github/GithubObject.py:334: error: Never has no attribute "items" [attr-defined]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/cookiejar.py:178:23: error: Incompatible types in assignment (expression has type "ItemsView[str, str | BaseCookie[str] | Morsel[Any]] | ItemsView[tuple[str, str | BaseCookie[str] | Morsel[Any]], Any] | ItemsView[Any, Any] | dict_items[str, Morsel[str]]", variable has type "Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str]") [assignment]
+ aiohttp/cookiejar.py:180:9: error: Unpacking a string is disallowed [misc]
+ aiohttp/client_reqrep.py:412:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:412:19: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-index for more info
+ aiohttp/client_reqrep.py:414:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:414:19: note: Error code "index" not covered by "type: ignore" comment
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/middleware/shared_data.py:120: error: Incompatible types in assignment (expression has type "dict_items[Tuple[str, Union[str, Tuple[str, str]]], Any]", variable has type "Union[Dict[str, Union[str, Tuple[str, str]]], Iterable[Tuple[str, Union[str, Tuple[str, str]]]]]") [assignment]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_collections.py:352: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "str") [assignment]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/elements/media.py: note: In function "marshall_video":
+ lib/streamlit/elements/media.py:508:35: error: Never has no attribute "items" [attr-defined]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/utils/datatypes.py:97: error: Unpacking a string is disallowed [misc]
+ scrapy/utils/datatypes.py:97: error: Value of type variable "AnyStr" of "normkey" of "CaselessDict" cannot be "int | bytes" [type-var]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/http/headers.py:48: error: Unpacking a string is disallowed [misc]
+ scrapy/http/headers.py:49: error: Value of type variable "AnyStr" of "normkey" of "Headers" cannot be "int | bytes" [type-var]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:131: error: Incompatible return value type (got "tuple[Any, ...] | tuple[V, ...]", expected "tuple[V]") [return-value]
Diff from mypy_primer, showing the effect of this PR on open source code:
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:593: error: Generator has incompatible item type "tuple[None, bytes]"; expected "tuple[bytes, bytes]" [misc]
+ mitmproxy/http.py:594: error: Argument 1 to "always_bytes" has incompatible type "str | bytes | Any | tuple[bytes, bytes]"; expected "None" [arg-type]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/filters.py:166: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[str, Any] | dict_items[tuple[str, Any], Any]", variable has type "Iterable[tuple[str, Any]]") [assignment]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/date/array.py:105: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:106: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:107: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "iteritems":
+ bidict/_iter.py:25:9: error: Incompatible types in "yield from" (actual type "tuple[Any, Any] | tuple[tuple[KT, VT], Any]", expected type "tuple[KT, VT]") [misc]
antidote (https://github.com/Finistere/antidote)
+ src/antidote/lib/interface_ext/_interface.py:531: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/cli/cloud/__init__.py:197: error: Incompatible types in assignment (expression has type "Hashable", variable has type "Sequence[Hashable]") [assignment]
mypy (https://github.com/python/mypy)
+ mypy/types.py:3582: error: Redundant cast to "List[Type]" [redundant-cast]
+ mypy/types.py:3582: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:206: error: Incompatible return value type (got "Any | Exception", expected "ResponseError") [return-value]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/helpers.py:123: error: Argument 1 to "append" of "list" has incompatible type "tuple[str, int | str | Mapping[str, Any]]"; expected "tuple[str, int]" [arg-type]
+ pymongo/cursor.py:798: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
+ pymongo/cursor.py:820: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
jax (https://github.com/google/jax)
- jax/_src/interpreters/xla.py:95: error: Unused "type: ignore" comment [unused-ignore]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/reactor/subhandling.py:70: error: Argument "id" to "generate_id" has incompatible type "Callable[[NamedArg(int, 'retry'), NamedArg(datetime, 'started'), NamedArg(timedelta, 'runtime'), NamedArg(Mapping[str, str], 'annotations'), NamedArg(Mapping[str, str], 'labels'), NamedArg(Body, 'body'), NamedArg(Meta, 'meta'), NamedArg(Spec, 'spec'), NamedArg(Status, 'status'), NamedArg(Resource, 'resource'), NamedArg(str | None, 'uid'), NamedArg(str | None, 'name'), NamedArg(str | None, 'namespace'), NamedArg(Patch, 'patch'), NamedArg(str, 'reason'), NamedArg(Diff, 'diff'), NamedArg(BodyEssence | Any | None, 'old'), NamedArg(BodyEssence | Any | None, 'new'), NamedArg(Logger | LoggerAdapter[Any], 'logger'), NamedArg(Any, 'memo'), DefaultNamedArg(Any, 'param'), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"; expected "str | None" [arg-type]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/process.py: note: In function "relocateOutputs":
+ cwltool/process.py:330:51: error: Argument 1 to "_collectDirEntries" has incompatible type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected "CWLObjectType | MutableSequence[CWLObjectType] | None" [arg-type]
+ tests/test_examples.py: note: In function "test_factory_partial_scatter":
+ tests/test_examples.py:327:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:327:12: note: Possible overload variants:
+ tests/test_examples.py:327:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:327:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:327:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:327:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:328:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:328:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:329:12: note: Possible overload variants:
+ tests/test_examples.py:329:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:329:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:329:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_factory_partial_output":
+ tests/test_examples.py:342:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:342:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:342:12: note: Possible overload variants:
+ tests/test_examples.py:342:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:342:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:342:27: error: Invalid index type "str" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_scatter_output_filenames":
+ tests/test_examples.py:1639:21: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" [type-var]
+ tests/test_examples.py:1639:28: error: Value of type "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:1639:28: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:1639:28: note: Possible overload variants:
+ tests/test_examples.py:1639:28: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:1639:28: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:1639:36: error: Invalid index type "str" for "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:1639:63: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1642:13: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
spark (https://github.com/apache/spark)
+ python/pyspark/ml/linalg/__init__.py:603: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/sql/connect/expressions.py:941: error: Argument 1 to "join" of "str" has incompatible type "list[UnresolvedNamedLambdaVariable]"; expected "Iterable[str]" [arg-type]
+ python/pyspark/mllib/linalg/__init__.py:661: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/ml/functions.py:288: error: Incompatible types in assignment (expression has type "list[Any]", target has type "ndarray[Any, Any]") [assignment]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/cookiejar.py:178:23: error: Incompatible types in assignment (expression has type "ItemsView[str, str | BaseCookie[str] | Morsel[Any]] | ItemsView[tuple[str, str | BaseCookie[str] | Morsel[Any]], Any] | ItemsView[Any, Any] | dict_items[str, Morsel[str]]", variable has type "Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str]") [assignment]
+ aiohttp/cookiejar.py:180:9: error: Unpacking a string is disallowed [misc]
+ aiohttp/client_reqrep.py:412:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:412:19: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-index for more info
+ aiohttp/client_reqrep.py:414:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:414:19: note: Error code "index" not covered by "type: ignore" comment
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/middleware/shared_data.py:120: error: Incompatible types in assignment (expression has type "Union[dict_items[str, Union[str, Tuple[str, str]]], dict_items[Tuple[str, Union[str, Tuple[str, str]]], Any]]", variable has type "Union[Dict[str, Union[str, Tuple[str, str]]], Iterable[Tuple[str, Union[str, Tuple[str, str]]]]]") [assignment]
+ src/werkzeug/middleware/shared_data.py:122: error: Unpacking a string is disallowed [misc]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/elements/widgets/time_widgets.py: note: In function "_parse_date_value":
+ lib/streamlit/elements/widgets/time_widgets.py:94:25: error: List comprehension has incompatible type List[Union[date, None, Any]]; expected List[date] [misc]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/utils/datatypes.py:97: error: Unpacking a string is disallowed [misc]
+ scrapy/utils/datatypes.py:97: error: Value of type variable "AnyStr" of "normkey" of "CaselessDict" cannot be "int | bytes" [type-var]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/http/headers.py:48: error: Unpacking a string is disallowed [misc]
+ scrapy/http/headers.py:49: error: Value of type variable "AnyStr" of "normkey" of "Headers" cannot be "int | bytes" [type-var]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:131: error: Incompatible return value type (got "tuple[Any, ...] | tuple[V, ...]", expected "tuple[V]") [return-value]
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_collections.py:352: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "str") [assignment]
So, Pyright and (changed) Mypy behave identically, except for the unnecessary
dict[Any, Any]
returned by Mypy. I will check if this has to do with the proposed changes.
After a few modifications, this PR leads to a narrowing completely consistent with Pyright for the discussed example:
from typing import Iterable
def f(x: dict[str, str] | Iterable[bytes]) -> None:
if isinstance(x, dict):
reveal_type(x)
- Pyright: Type of "x" is "dict[str, str] | dict[bytes, Unknown]"
-
Pyre: Revealed type [-1]: Revealed type for
x
istyping.Dict[str, str]
. - Mypy: Revealed type is "Union[builtins.dict[builtins.str, builtins.str], builtins.dict[builtins.bytes, Any]]"
The primer's response is nearly the same as the one analysed by @TeamSpen210. The differences between both primer outputs are due to different item orders in unions and the removal of unnecessary "any generics" like in the discussed example.
So, this PR seems ready for a more complete review.
An additional thought. Wouldn't it be preferable to warn more strictly that type narrowing results in code that is not type-safe? Maybe the --disallow-any-generics
option is a candidate for enabling warnings like this:
# mypy: disallow-any-generics
from typing import Iterable
def f(x: Iterable[str]) -> None:
if isinstance(x, dict): # E: Iterable[str] does not provide parameters for all type variables of generic type "dict"
x["I must be string"] = "I could be number"
Sorry I've been quiet on this; I've had a nasty bug for the past 10 days or so.
Is there anything I can do to help this along?
Thanks for offering help!
I think this is generally ready for a maintainer's review. Luckily, @hauntsaninja seems to have it already on his list. But if you have time and motivation, checking and eventually extending the new tests so that they cover as many potential flaws of this PR as possible would be nice. That would increase my confidence in not introducing a nasty 10-day bug in Mypy...
I suspect I've re-discovered this bug again, with the following code:
from __future__ import annotations
from typing import (
Sequence,
Tuple,
Union,
)
class Class1: pass
class Class2: pass
class Class3: pass
Class1Spec = Union[Class1, Tuple[Class2, Class3]]
def some_func(steps: Union[Class1Spec, Sequence[Class1Spec]]) -> None:
if isinstance(steps, tuple):
reveal_type(steps)
# got: Tuple[Any, ...]
# expected: Union[
# Tuple[Class2, Class3],
# Tuple[
# Class1Spec=Union[Class1, Tuple[Class2, Class3],
# ...
# ],
# ]
else:
reveal_type(steps)
# as expected (only Tuple[Class2, Class3] is eliminated)
I've tried to verify this is fixed using @tyralla's branch, but the first reveal_type()
at line 17 is giving:
Union[Tuple[Any, ...], Tuple[Union[Class1, Tuple[Class2, Class3]], ...]]
rather than
Union[Tuple[Class2, Class3], Tuple[Union[Class1, Tuple[Class2, Class3]], ...]]
Without the patch, it gives:
Tuple[Any, ...]
Thank you for finding this limitation (does "re-discovered" mean it's already reported?). This is because tuples are represented by TupleType
instead of Instance
, and this PR only captures (unions of) Instance
for the current type. A simpler repro for the current state of this PR:
[case testKeepTypeVarArgsWhenNarrowingGenericsToTupleType]
from typing import Sequence, Tuple, Union
class C: ...
x: Union[Tuple[C], Sequence[Tuple[C]]]
if isinstance(x, tuple):
reveal_type(x) # N: Revealed type is "Union[builtins.tuple[Any, ...], builtins.tuple[Tuple[__main__.C], ...]]"
else:
reveal_type(x) # N: Revealed type is "typing.Sequence[Tuple[__main__.C]]"
[builtins fixtures/tuple.pyi]
@tyralla I was thinking "rediscovered" as in "this is a special case of #17099". If it's not, and it doesn't make sense to tack the extra work onto this PR, I'll file a separate issue.
No, I thought about it and now believe it should be included in this PR. I did this in a simple manner without considering that one could narrow a tuple to a tuple subclass (this should not happen often and seems more challenging to implement; I left a code comment).
The test case testKeepTypeVarArgsWhenNarrowingTupleTypeToTuple
checks this additional feature.
Diff from mypy_primer, showing the effect of this PR on open source code:
mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/http.py:593: error: Generator has incompatible item type "tuple[None, bytes]"; expected "tuple[bytes, bytes]" [misc]
+ mitmproxy/http.py:594: error: Argument 1 to "always_bytes" has incompatible type "str | bytes | Any | tuple[bytes, bytes]"; expected "None" [arg-type]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/filters.py:166: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[str, Any] | dict_items[tuple[str, Any], Any]", variable has type "Iterable[tuple[str, Any]]") [assignment]
pandas (https://github.com/pandas-dev/pandas)
+ pandas/tests/extension/date/array.py:105: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:106: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
+ pandas/tests/extension/date/array.py:107: error: Item "date" of "date | Any" has no attribute "astype" [union-attr]
bidict (https://github.com/jab/bidict)
+ bidict/_iter.py: note: In function "iteritems":
+ bidict/_iter.py:25:9: error: Incompatible types in "yield from" (actual type "tuple[Any, Any] | tuple[tuple[KT, VT], Any]", expected type "tuple[KT, VT]") [misc]
antidote (https://github.com/Finistere/antidote)
+ src/antidote/lib/interface_ext/_interface.py:531: error: Unused "type: ignore" comment [unused-ignore]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/cli/cloud/__init__.py:198: error: Incompatible types in assignment (expression has type "Hashable", variable has type "Sequence[Hashable]") [assignment]
mypy (https://github.com/python/mypy)
+ mypy/types.py:3582: error: Redundant cast to "List[Type]" [redundant-cast]
+ mypy/types.py:3582: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-redundant-cast for more info
aioredis (https://github.com/aio-libs/aioredis)
+ aioredis/connection.py:206: error: Incompatible return value type (got "Any | Exception", expected "ResponseError") [return-value]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/reactor/subhandling.py:70: error: Argument "id" to "generate_id" has incompatible type "Callable[[NamedArg(int, 'retry'), NamedArg(datetime, 'started'), NamedArg(timedelta, 'runtime'), NamedArg(Mapping[str, str], 'annotations'), NamedArg(Mapping[str, str], 'labels'), NamedArg(Body, 'body'), NamedArg(Meta, 'meta'), NamedArg(Spec, 'spec'), NamedArg(Status, 'status'), NamedArg(Resource, 'resource'), NamedArg(str | None, 'uid'), NamedArg(str | None, 'name'), NamedArg(str | None, 'namespace'), NamedArg(Patch, 'patch'), NamedArg(str, 'reason'), NamedArg(Diff, 'diff'), NamedArg(BodyEssence | Any | None, 'old'), NamedArg(BodyEssence | Any | None, 'new'), NamedArg(Logger | LoggerAdapter[Any], 'logger'), NamedArg(Any, 'memo'), DefaultNamedArg(Any, 'param'), KwArg(Any)], object | Coroutine[None, None, object | None] | None]"; expected "str | None" [arg-type]
spark (https://github.com/apache/spark)
+ python/pyspark/ml/linalg/__init__.py:603: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/sql/connect/expressions.py:941: error: Argument 1 to "join" of "str" has incompatible type "list[UnresolvedNamedLambdaVariable]"; expected "Iterable[str]" [arg-type]
+ python/pyspark/mllib/linalg/__init__.py:661: error: Incompatible types in assignment (expression has type "dict_items[Any, Any] | dict_items[float, Any] | dict_items[int, float] | dict_items[tuple[int, float], Any]", variable has type "bytes | tuple[int, float] | Iterable[float] | Iterable[tuple[int, float]] | dict[int, float]") [assignment]
+ python/pyspark/ml/functions.py:291: error: Incompatible types in assignment (expression has type "list[Any]", target has type "ndarray[Any, Any]") [assignment]
cwltool (https://github.com/common-workflow-language/cwltool)
+ cwltool/process.py: note: In function "relocateOutputs":
+ cwltool/process.py:330:51: error: Argument 1 to "_collectDirEntries" has incompatible type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected "CWLObjectType | MutableSequence[CWLObjectType] | None" [arg-type]
+ tests/test_examples.py: note: In function "test_factory_partial_scatter":
+ tests/test_examples.py:327:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:327:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:327:12: note: Possible overload variants:
+ tests/test_examples.py:327:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:327:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:327:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:327:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:328:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:328:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: Value of type "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:329:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:329:12: note: Possible overload variants:
+ tests/test_examples.py:329:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:329:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:329:26: error: Invalid index type "int" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "str" [index]
+ tests/test_examples.py:329:29: error: Invalid index type "str" for "str | Any | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_factory_partial_output":
+ tests/test_examples.py:342:12: error: Value of type "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None" is not indexable [index]
+ tests/test_examples.py:342:12: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:342:12: note: Possible overload variants:
+ tests/test_examples.py:342:12: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:342:12: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:342:27: error: Invalid index type "str" for "str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | Any | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py: note: In function "test_scatter_output_filenames":
+ tests/test_examples.py:1639:21: error: Value of type variable "SupportsRichComparisonT" of "sorted" cannot be "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" [type-var]
+ tests/test_examples.py:1639:28: error: Value of type "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" is not indexable [index]
+ tests/test_examples.py:1639:28: error: No overload variant of "__getitem__" of "MutableSequence" matches argument type "str" [call-overload]
+ tests/test_examples.py:1639:28: note: Possible overload variants:
+ tests/test_examples.py:1639:28: note: def __getitem__(self, int, /) -> CWLOutputType
+ tests/test_examples.py:1639:28: note: def __getitem__(self, slice, /) -> MutableSequence[CWLOutputType]
+ tests/test_examples.py:1639:36: error: Invalid index type "str" for "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None"; expected type "SupportsIndex | slice" [index]
+ tests/test_examples.py:1639:63: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1639:63: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "__iter__" (not iterable) [union-attr]
+ tests/test_examples.py:1642:13: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1642:13: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1643:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "None" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "int" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "float" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableSequence[CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
+ tests/test_examples.py:1644:17: error: Item "MutableMapping[str, CWLOutputType]" of "Any | str | int | float | MutableSequence[CWLOutputType] | MutableMapping[str, CWLOutputType] | None" has no attribute "endswith" [union-attr]
jax (https://github.com/google/jax)
- jax/_src/interpreters/xla.py:95: error: Unused "type: ignore" comment [unused-ignore]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
+ pymongo/helpers.py:126: error: Argument 1 to "append" of "list" has incompatible type "tuple[str, int | str | Mapping[str, Any]]"; expected "tuple[str, int]" [arg-type]
+ pymongo/cursor.py:798: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
+ pymongo/cursor.py:820: error: Argument 1 to "dict" has incompatible type "list[str | tuple[str, int | str | Mapping[str, Any]]] | list[Any] | tuple[str | tuple[str, int | str | Mapping[str, Any]], ...] | tuple[Any, ...]"; expected "Iterable[tuple[str | Any, Any]]" [arg-type]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/cookiejar.py:178:23: error: Incompatible types in assignment (expression has type "ItemsView[str, str | BaseCookie[str] | Morsel[Any]] | ItemsView[tuple[str, str | BaseCookie[str] | Morsel[Any]], Any] | ItemsView[Any, Any] | dict_items[str, Morsel[str]]", variable has type "Mapping[str, str | BaseCookie[str] | Morsel[Any]] | Iterable[tuple[str, str | BaseCookie[str] | Morsel[Any]]] | BaseCookie[str]") [assignment]
+ aiohttp/cookiejar.py:180:9: error: Unpacking a string is disallowed [misc]
+ aiohttp/client_reqrep.py:412:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:412:19: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-index for more info
+ aiohttp/client_reqrep.py:414:19: error: Invalid index type "str | Any | tuple[str, str | BaseCookie[str] | Morsel[Any]]" for "SimpleCookie"; expected type "str" [index]
+ aiohttp/client_reqrep.py:414:19: note: Error code "index" not covered by "type: ignore" comment
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/_collections.py:352: error: Incompatible types in assignment (expression has type "tuple[str, str]", variable has type "str") [assignment]
werkzeug (https://github.com/pallets/werkzeug)
+ src/werkzeug/middleware/shared_data.py:120: error: Incompatible types in assignment (expression has type "dict_items[str, str | tuple[str, str]] | dict_items[tuple[str, str | tuple[str, str]], Any]", variable has type "dict[str, str | tuple[str, str]] | Iterable[tuple[str, str | tuple[str, str]]]") [assignment]
+ src/werkzeug/middleware/shared_data.py:122: error: Unpacking a string is disallowed [misc]
streamlit (https://github.com/streamlit/streamlit)
+ lib/streamlit/elements/widgets/time_widgets.py: note: In function "_parse_date_value":
+ lib/streamlit/elements/widgets/time_widgets.py:94:25: error: List comprehension has incompatible type List[Union[date, None, Any]]; expected List[date] [misc]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/utils/datatypes.py:96: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/utils/datatypes.py:97: error: Unpacking a string is disallowed [misc]
+ scrapy/utils/datatypes.py:97: error: Value of type variable "AnyStr" of "normkey" of "CaselessDict" cannot be "int | bytes" [type-var]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[str, Any]] | ItemsView[tuple[str, Any], Any]", variable has type "Mapping[str, Any] | Iterable[tuple[str, Any]]") [assignment]
+ scrapy/http/headers.py:46: error: Incompatible types in assignment (expression has type "Iterable[tuple[bytes, Any]] | ItemsView[tuple[bytes, Any], Any]", variable has type "Mapping[bytes, Any] | Iterable[tuple[bytes, Any]]") [assignment]
+ scrapy/http/headers.py:48: error: Unpacking a string is disallowed [misc]
+ scrapy/http/headers.py:49: error: Value of type variable "AnyStr" of "normkey" of "Headers" cannot be "int | bytes" [type-var]
ibis (https://github.com/ibis-project/ibis)
+ ibis/util.py:131: error: Incompatible return value type (got "tuple[Any, ...] | tuple[V, ...]", expected "tuple[V]") [return-value]
The new primer output is practically identical to the last one.