Skip to content
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

asyncio.StreamWriter.transport not specific enough #7610

Closed
Akuli opened this issue Apr 9, 2022 · 0 comments · Fixed by #7611
Closed

asyncio.StreamWriter.transport not specific enough #7610

Akuli opened this issue Apr 9, 2022 · 0 comments · Fixed by #7611
Labels
topic: asyncio Asyncio-related issues

Comments

@Akuli
Copy link
Collaborator

Akuli commented Apr 9, 2022

This works at runtime:

import asyncio

async def handle_connection(reader: asyncio.StreamReader, writer: asyncio.StreamWriter) -> None:
    print(writer.transport.get_write_buffer_size())
    writer.write(b"x" * (256*1024*1024))
    print(writer.transport.get_write_buffer_size())

async def main() -> None:
    async with await asyncio.start_server(handle_connection, port=1234) as server:
        await server.serve_forever()

asyncio.run(main())

but doesn't type check:

/tmp/echo2.py:4: error: "BaseTransport" has no attribute "get_write_buffer_size"
/tmp/echo2.py:6: error: "BaseTransport" has no attribute "get_write_buffer_size"

According to asyncio docs, a WriteTransport has a get_write_buffer_size() method, and guessing from the names of things, I think writer.transport should always be a WriteTransport.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: asyncio Asyncio-related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants