Closed
Description
Here's an example:
import asyncio
class MyProtocol(asyncio.Protocol):
def hello(self) -> None:
pass
async def f() -> None:
_, protocol = await asyncio.get_event_loop().create_connection(MyProtocol)
protocol.hello()
Mypy will say that error: "BaseProtocol" has no attribute "hello"
. That's because current stubs say that returned protocol type will be BaseProtocol
. But we know for sure it will be the same as a type of the value returned by protocol factory (first argument).
It could be made like this:
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
async def create_connection(self, protocol_factory: Callable[[], _ProtocolT], ...) -> tuple[BaseTransport, _ProtocolT]:
This way type checking will be more precise and there will be no need for casts. What to you think?