Avoid Any specializations for covariant and contravariant type variables inside TypeIs returns#14784
Avoid Any specializations for covariant and contravariant type variables inside TypeIs returns#14784AlexWaygood wants to merge 1 commit intomainfrom
Any specializations for covariant and contravariant type variables inside TypeIs returns#14784Conversation
…ables inside `TypeIs` returns
|
Diff from mypy_primer, showing the effect of this PR on open source code: pandera (https://github.com/pandera-dev/pandera)
+ pandera/dtypes.py:561: error: Unused "type: ignore" comment [unused-ignore]
+ tests/pandas/test_dtypes.py:300: error: Item "object" of "object | Any" has no attribute "foo" [union-attr]
graphql-core (https://github.com/graphql-python/graphql-core)
+ tests/execution/test_middleware.py:274: error: "object" has no attribute "data" [attr-defined]
+ tests/execution/test_middleware.py:276: error: "object" has no attribute "data" [attr-defined]
trio (https://github.com/python-trio/trio)
+ src/trio/_core/_tests/test_ki.py:685: error: Argument 1 to "_consume_async_generator" has incompatible type "AsyncGeneratorType[object, Never]"; expected "AsyncGenerator[None, None]" [arg-type]
+ src/trio/_core/_tests/test_ki.py:690: error: Argument 1 to "send" of "GeneratorType" has incompatible type "None"; expected "Never" [arg-type]
+ src/trio/_core/_tests/test_ki.py:690: error: Argument 1 to "send" of "CoroutineType" has incompatible type "None"; expected "Never" [arg-type]
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/third_party/beartype.py:125: error: Cannot assign to a method [method-assign]
svcs (https://github.com/hynek/svcs)
+ src/svcs/_core.py:459: error: "Awaitable[Any]" not callable [operator]
+ src/svcs/_core.py:492: error: "Awaitable[Any]" not callable [operator]
psycopg (https://github.com/psycopg/psycopg)
+ psycopg_pool/psycopg_pool/_acompat.py:184: error: Incompatible types in assignment (expression has type "object", variable has type "T | Coroutine[Any, Any, T]") [assignment]
+ psycopg_pool/psycopg_pool/_acompat.py:185: error: Incompatible return value type (got "T | Coroutine[Any, Any, T]", expected "T") [return-value]
core (https://github.com/home-assistant/core)
+ homeassistant/core.py:596: error: Argument 1 to "HassJob" has incompatible type "Callable[[VarArg(*_Ts)], Any] | Coroutine[Any, Any, Any]"; expected "Callable[[VarArg(*_Ts)], Any]" [arg-type]
+ homeassistant/core.py:661: error: Argument 1 to "HassJob" has incompatible type "Callable[[VarArg(*_Ts)], Coroutine[Any, Any, _R] | _R] | Coroutine[Any, Any, _R]"; expected "Callable[[VarArg(*_Ts)], Coroutine[Any, Any, _R] | _R]" [arg-type]
+ homeassistant/core.py:661: error: Argument 1 to "HassJob" has incompatible type "Callable[[VarArg(*_Ts)], Coroutine[Any, Any, _R] | _R] | Coroutine[Any, Any, _R]"; expected "Callable[[VarArg(Any), KwArg(Any)], Coroutine[Any, Any, _R]]" [arg-type]
+ homeassistant/core.py:988: error: Argument 1 to "HassJob" has incompatible type "Callable[[VarArg(*_Ts)], Coroutine[Any, Any, _R] | _R] | Coroutine[Any, Any, _R]"; expected "Callable[[VarArg(*_Ts)], Coroutine[Any, Any, _R] | _R]" [arg-type]
+ homeassistant/core.py:988: error: Argument 1 to "HassJob" has incompatible type "Callable[[VarArg(*_Ts)], Coroutine[Any, Any, _R] | _R] | Coroutine[Any, Any, _R]"; expected "Callable[[VarArg(Any), KwArg(Any)], Coroutine[Any, Any, _R]]" [arg-type]
+ homeassistant/helpers/entity_platform.py:448: error: Argument 1 to "create_eager_task" has incompatible type "Coroutine[object, Never, object]"; expected "Coroutine[Any, Any, None]" [arg-type]
anyio (https://github.com/agronholm/anyio)
+ src/anyio/from_thread.py:267: error: Argument 1 to "set_result" of "Future" has incompatible type "object"; expected "T_Retval" [arg-type]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/flow_engine.py:929: error: Incompatible types in assignment (expression has type "object", variable has type "Union[R, type[NotSet]]") [assignment]
+ src/prefect/input/run_input.py:355: error: "object" has no attribute "value" [attr-defined]
+ src/prefect/input/run_input.py:481: error: Incompatible return value type (got "object", expected "R") [return-value]
+ src/prefect/input/run_input.py:500: error: "object" has no attribute "__iter__"; maybe "__dir__" or "__str__"? (not iterable) [attr-defined]
+ src/prefect/input/run_input.py:502: error: Incompatible return value type (got "object", expected "list[FlowRunInput]") [return-value]
+ src/prefect/input/run_input.py:586: error: "object" has no attribute "__iter__"; maybe "__dir__" or "__str__"? (not iterable) [attr-defined]
+ src/prefect/input/run_input.py:588: error: Incompatible return value type (got "object", expected "list[FlowRunInput]") [return-value]
- src/prefect/cli/deployment.py:292: error: R? has no attribute "model_dump" [attr-defined]
+ src/prefect/concurrency/v1/sync.py:63: error: Argument 1 to "emit_concurrency_acquisition_events" has incompatible type "Coroutine[Any, Any, R?]"; expected "list[MinimalConcurrencyLimitResponse]" [arg-type]
+ src/prefect/concurrency/v1/sync.py:69: error: Value of type "Coroutine[Any, Any, R?]" must be used [unused-coroutine]
+ src/prefect/concurrency/v1/sync.py:69: note: Are you missing an await?
+ src/prefect/concurrency/v1/sync.py:72: error: Argument 1 to "emit_concurrency_release_events" has incompatible type "Coroutine[Any, Any, R?]"; expected "list[MinimalConcurrencyLimitResponse]" [arg-type]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/defer.py:560: error: Incompatible return value type (got "_T | Awaitable[_T]", expected "Awaitable[_T]") [return-value]
+ scrapy/cmdline.py:77: error: Incompatible types in assignment (expression has type "object", target has type "ScrapyCommand") [assignment]
strawberry (https://github.com/strawberry-graphql/strawberry)
+ strawberry/utils/await_maybe.py:13: error: Incompatible return value type (got "object", expected "T") [return-value]
+ strawberry/types/object_type.py:306: error: Value of type variable "T" of "_inject_default_for_maybe_annotations" cannot be "object" [type-var]
+ strawberry/types/object_type.py:307: error: Value of type variable "T" of "_wrap_dataclass" cannot be "object" [type-var]
+ strawberry/relay/fields.py:344: error: Incompatible types in assignment (expression has type "object", variable has type "Awaitable[Any]") [assignment]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/utils.py:703: error: Incompatible return value type (got "object", expected "T") [return-value]
aiohttp-devtools (https://github.com/aio-libs/aiohttp-devtools)
+ aiohttp_devtools/runserver/config.py:240: error: Incompatible types in assignment (expression has type "object", variable has type "Application | Awaitable[Application]") [assignment]
pytest (https://github.com/pytest-dev/pytest)
+ testing/test_monkeypatch.py:420: error: Statement is unreachable [unreachable]
steam.py (https://github.com/Gobot1234/steam.py)
+ steam/utils.py:894: error: Incompatible return value type (got "object", expected "_T") [return-value]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/web.py:307:15: error: Incompatible types in assignment (expression has type "object", variable has type "Application | Awaitable[Application]") [assignment]
|
This is inside a
What's happening here is that:
And that type should in turn be simplifable to All of which to is to say that the inferred type of |
These look like true positives.
A true positive that mypy didn't catch previously because it narrowed the type to
These again seem to be due to mypy having an imperfect understanding of intersections... the type of |
Looks like another case of mypy not simplify |
No description provided.