Skip to content

gh-150358 Remove unused _complete_fut attribute from asyncio.StreamWriter#150359

Open
deadlovelll wants to merge 1 commit into
python:mainfrom
deadlovelll:gh-150358-streamreader-dead-complete_fut
Open

gh-150358 Remove unused _complete_fut attribute from asyncio.StreamWriter#150359
deadlovelll wants to merge 1 commit into
python:mainfrom
deadlovelll:gh-150358-streamreader-dead-complete_fut

Conversation

@deadlovelll
Copy link
Copy Markdown
Contributor

@deadlovelll deadlovelll commented May 24, 2026

asyncio.StreamWriter.__init__ allocates and resolves a Future and stores it as self._complete_fut, but the attribute is never read anywhere in CPython.

Before:

def __init__(self, transport, protocol, reader, loop):
    self._transport = transport
    self._protocol = protocol
    assert reader is None or isinstance(reader, StreamReader)
    self._reader = reader
    self._loop = loop
    self._complete_fut = self._loop.create_future()
    self._complete_fut.set_result(None)

After:

def __init__(self, transport, protocol, reader, loop):
    self._transport = transport
    self._protocol = protocol
    assert reader is None or isinstance(reader, StreamReader)
    self._reader = reader
    self._loop = loop

The StreamWriter class is used by functions such as: asyncio.open_connection, asyncio.start_server, asyncio.open_unix_connection, asyncio.start_unix_server. So the allocation of an unused future happens on every asyncio network connection

No behavior change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant