gh-149740: Remove redundant self.empty() check in asyncio.Queue.get()#149741
gh-149740: Remove redundant self.empty() check in asyncio.Queue.get()#149741deadlovelll wants to merge 1 commit into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
I don't think it's correct. See the issue. |
|
Looking at the other parts of the code, I think it would make indeed more sense to consistently raise on shutdown whether the queue is empty or not. So it is not dead code but it rathet looks like a bug to me. |
| """ | ||
| while self.empty(): | ||
| if self._is_shutdown and self.empty(): | ||
| if self._is_shutdown: |
There was a problem hiding this comment.
You could just change the loop to while self.empty() and not self._is_shutdown:; get_nowait already rechecks all this stuff when it's called, and would raise the necessary exception for us.
There was a problem hiding this comment.
I would prefer keeping this as is, so to keep the symmetry in the get() method.
Bug description:
In
Lib/asyncio/queues.py,Queue.get()contains a redundant call toself.empty()inside its waiting loop: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():This PR is cleanup only, no behavior change