-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Avoid Any specializations for covariant and contravariant type variables inside TypeIs returns
#14784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…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.