Skip to content

Remove unused _complete_fut attribute from asyncio.StreamWriter #150358

Description

@deadlovelll

Bug report

Bug description:

asyncio.StreamWriter.__init__ creates a _complete_fut Future and stores it on the instance:

# Lib/asyncio/streams.py
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)

The StreamWriter class is used by functios 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

The attribute is not read anywhere in CPython. The project search returned only two lines in StreamWriter.__init__

Proposed change:

Drop the two _complete_fut lines:

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

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-refactorCode refactoring (with no changes in behavior)

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions