Skip to content

Redundant self.empty() check in asyncio.Queue.get() #149740

@deadlovelll

Description

@deadlovelll

Bug report

Bug description:

Bug description:

In Lib/asyncio/queues.py, Queue.get() contains a redundant call to self.empty() inside its waiting loop:

async def get(self):
    while self.empty():
        if self._is_shutdown and self.empty():   # second self.empty() is redundant
            raise QueueShutDown

self.empty() is guaranteed to be true by the enclosing while self.empty() the loop body cannot execute otherwise. This check is a dead code.

Proposed fix:

Drop the redundant and self.empty():

while self.empty():
    if self._is_shutdown:
        raise QueueShutDown

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions