-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
Consider a custom datagram-only asyncio protocol:
import asyncio
class MyProtocol(asyncio.DatagramProtocol):
def connection_made(self, transport: asyncio.BaseTransport): # signature as per typeshed super class
if not isinstance(transport, asyncio.DatagramTransport):
raise TypeError("%s not supported because it's not a datagram transport." % type(transport))
# ...
For UDP connections on Linux, the above code results in
TypeError: <class 'asyncio.selector_events._SelectorDatagramTransport'> not supported because it's not a datagram transport.
Per implementation, class _SelectorDatagramTransport is a structural subtype of class DatagramTransport, but it does not actually inherit. However, from a users perspective I'd say both static and runtime type checks should succeed.
I'm unsure if the required change would have to go to cpython (let _SelectorDatagramTransport
inherit DatagramTransport
) or to typeshed (define BaseTransport
and DatagramTransport
as typing.Protocol
with @runtime_checkable
). What would you say?
If you think this is a valid request, I could try a PR.
Metadata
Metadata
Assignees
Labels
No labels