Experiment: use upper bound instead of Any for TypeIs[Generic[Any]] in stdlib - #16108
Draft
randolf-scholz wants to merge 1 commit into
Draft
Experiment: use upper bound instead of Any for TypeIs[Generic[Any]] in stdlib#16108randolf-scholz wants to merge 1 commit into
Any for TypeIs[Generic[Any]] in stdlib#16108randolf-scholz wants to merge 1 commit into
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: 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]
steam.py (https://github.com/Gobot1234/steam.py)
+ steam/utils.py:894: 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]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/flow_engine.py:1464: error: Incompatible types in assignment (expression has type "object", variable has type "R | type[NotSet]") [assignment]
+ src/prefect/concurrency/v1/sync.py:63: error: Argument 1 to "emit_concurrency_acquisition_events" has incompatible type "list[MinimalConcurrencyLimitResponse] | Coroutine[Any, Any, list[MinimalConcurrencyLimitResponse]]"; expected "list[MinimalConcurrencyLimitResponse]" [arg-type]
+ src/prefect/concurrency/v1/sync.py:72: error: Argument 1 to "emit_concurrency_release_events" has incompatible type "list[MinimalConcurrencyLimitResponse] | Coroutine[Any, Any, list[MinimalConcurrencyLimitResponse]]"; expected "list[MinimalConcurrencyLimitResponse]" [arg-type]
+ src/prefect/cli/deployment.py:215: error: "object" has no attribute "model_dump" [attr-defined]
strawberry (https://github.com/strawberry-graphql/strawberry)
+ strawberry/utils/await_maybe.py:13: error: Incompatible return value type (got "object", expected "T") [return-value]
aiohttp (https://github.com/aio-libs/aiohttp)
+ aiohttp/web.py:295:15: error: Incompatible types in assignment (expression has type "object", variable has type "Application | Awaitable[Application]") [assignment]
scrapy (https://github.com/scrapy/scrapy)
+ scrapy/utils/defer.py:576: error: Incompatible return value type (got "_T | Awaitable[_T]", expected "Awaitable[_T]") [return-value]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/utils.py:714: error: Incompatible return value type (got "object", expected "T") [return-value]
trio (https://github.com/python-trio/trio)
+ src/trio/_core/_tests/test_ki.py:687: error: Argument 1 to "send" of "CoroutineType" has incompatible type "None"; expected "Never" [arg-type]
anyio (https://github.com/agronholm/anyio)
+ src/anyio/from_thread.py:279: error: Argument 1 to "set_result" of "Future" has incompatible type "object"; expected "T_Retval" [arg-type]
kopf (https://github.com/nolar/kopf)
+ kopf/_core/intents/piggybacking.py:165: error: Incompatible types in assignment (expression has type "object", variable has type "str | None") [assignment]
paasta (https://github.com/yelp/paasta)
+ paasta_tools/async_utils.py:162: error: "None" has no attribute "close" [attr-defined]
|
Collaborator
|
Cc @AlexWaygood @JelleZijlstra, since you previously commented on this or changed the annotations. I agree that we should at least be consistent inside typeshed. |
Member
|
I think I tried this recently and decided to hold off on these? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following the discussion in #16051, if callable should return
TypeIs[Callable[..., object]], these methods logically should also useobjectfor their covariant andNeverfor their contravariant arguments rather thanAny.