-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Use PEP-646 in stubs for asyncio
#11015
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mypy_primer analysistornadoThey're subclassing websocketsThis is arguably a true positive: they're passing a function that expects an According to our stubs, typeshed/stdlib/asyncio/tasks.pyi Line 439 in aabeacf
blackI think their annotations are slightly incorrect: see psf/black#4047 discordI think their annotations are definitely incorrect. The code in question is here: https://github.com/Rapptz/discord.py/blob/a5d03d4a1e6f4314518f6f55d8b7130ab3f4336e/discord/ext/tasks/__init__.py#L107-L119. |
@AlexWaygood You marked this as ready for review, but it's still tagged as "deferred". Is the latter an oversight? |
It can't be merged until pytype no longer crashes whenever we use I merged |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I really like the additional type safety that Unpack
brings us. One complaint, though.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Oh, I thought #11120 would unblock this and #11014, but looks like I got mixed up :) google/pytype@bbf10c1 didn't quite make it into pytype==2023.12.7 -- it'll be included in the next pytype release. |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: tornado (https://github.com/tornadoweb/tornado)
+ tornado/platform/asyncio.py:705: error: Argument 3 of "add_reader" is incompatible with supertype "AbstractEventLoop"; supertype defines the argument type as "Unpack[_Ts]" [override]
+ tornado/platform/asyncio.py:705: note: This violates the Liskov substitution principle
+ tornado/platform/asyncio.py:705: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
+ tornado/platform/asyncio.py:710: error: Argument 3 of "add_writer" is incompatible with supertype "AbstractEventLoop"; supertype defines the argument type as "Unpack[_Ts]" [override]
+ tornado/platform/asyncio.py:710: note: This violates the Liskov substitution principle
+ tornado/platform/asyncio.py:710: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides
websockets (https://github.com/aaugustin/websockets)
+ src/websockets/legacy/async_timeout.py:239: error: Argument 1 to "call_soon" of "AbstractEventLoop" has incompatible type "Callable[[Task[None]], None]"; expected "Callable[[Task[Any] | None], object]" [arg-type]
+ src/websockets/legacy/async_timeout.py:241: error: Argument 2 to "call_at" of "AbstractEventLoop" has incompatible type "Callable[[Task[None]], None]"; expected "Callable[[Task[Any] | None], object]" [arg-type]
discord.py (https://github.com/Rapptz/discord.py)
+ discord/ext/tasks/__init__.py:114: error: Argument 2 to "call_later" of "AbstractEventLoop" has incompatible type "Callable[[None], None]"; expected "Callable[[bool], object]" [arg-type]
+ discord/ext/tasks/__init__.py:119: error: Argument 2 to "call_later" of "AbstractEventLoop" has incompatible type "Callable[[None], None]"; expected "Callable[[bool], object]" [arg-type]
|
And we're there! |
As with #11014, I think this will crash pytype for now -- but I'm curious to see the mypy_primer output