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
Wrong type hint for asyncio.base_events.Server sockets attribute #5535
Comments
I added type hints to the addr = server.sockets[0].getsockname() |
Quick check:
|
Also, |
It's worth noting that
|
* Move socket from AbstractServer to Server. * Fix Server.socket type on Python 3.7+. * Use Iterable instead of list for socket argument. Closes: python#5535
* Move socket from AbstractServer to Server. * Fix Server.socket type on Python 3.7+. * Use Iterable instead of list for socket argument. Closes: #5535
Thank you @srittau for addressing this so quickly! I saw you annotated the However, both examples that I mentioned from the standard library use it as a addr = server.sockets[0].getsockname() The examples are:
|
@ramalho The attributes/properties are annotated as |
I am sorry but don't understand your answer, @srittau. Yes, the annotation is compatible with the implementations, but the The documentation for
Users expect to be able to index a addr = server.sockets[0].getsockname() Therefore, the |
But the |
FYI, the code sample from the asyncio docs still does not type check because |
Also, should we make create_server() return a Server instead of an AbstractServer in the stub? |
That works but
That'd fix it for the top-level |
Cf. #5566. |
Great, thanks! |
The fix for issue #2364 ("AbstractServer" has no attribute "sockets") added this declaration:
However, in the Python 3.9 implementation of
asyncio.base_events.Server
,sockets
is a property defined like this:So we have two problems:
sockets
is neverNone
, it's always atuple
.tuple[TransportSocket, ...]
.There is example code in the
asyncio
docs and test code in the standard library that assumesockets
is a sequence of sockets.@ymyzk contributed the patch for #2364 noting "I noticed that this class has some changes in Python 3.7, so we need to update it again in the near future."
The documentation for
asyncio.Server.sockets
states:As I mentioned, the actual value returned is a tuple of zero or more
asyncio.Server.TransportSocket
objects.The text was updated successfully, but these errors were encountered: