Skip to content

Bad docs, or bad types for asyncio.WriteTransport? #5779

@jnsnow

Description

@jnsnow

I have to admit I am not fully certain of this one, there's a few layers of abstraction to sift through.

Typeshed declares this:

class _FlowControlMixin(Transport):
    def __init__(self, extra: Optional[Mapping[Any, Any]] = ..., loop: Optional[AbstractEventLoop] = ...) -> None: ...
    def get_write_buffer_limits(self) -> Tuple[int, int]: ...

Which does seem true: CPython does indeed define get_write_buffer_limits() as part of that _FlowControlMixin class. Where I lose the plot, however, is the fact that https://docs.python.org/3/library/asyncio-protocol.html#write-only-transports seems to imply that all asyncio.WriteTransport types will offer this method. In practice, I suppose that isn't strictly true, since the CPython implementation declares the class like this:

class WriteTransport(BaseTransport):
    ...

And does not in fact guarantee the presence of this method. It turns out that the actual type of the transport beneath the StreamWriter that I have is ... asyncio.selector_events._SelectorSocketTransport, which inherits from _SelectorTransport, which in turn inherits from transports._FlowControlMixin and transports.Transport, the latter of which inherits from both ReadTransport and WriteTransport.

Phew, OK.

I suppose this means the docs are "wrong" in the sense that WriteTransport does not necessarily guarantee the presence of this method, but "in practice" all implementations of WriteTransport use the _FlowControlMixin that offers it.

Does the WriteTransport class just need a NotImplementedError stub for get_write_buffer_limits() ...? or is it intentional that this method isn't required and the docs are wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions