This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nickdrozd
Recipients nickdrozd
Date 2021-12-03.23:15:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638573350.23.0.80297686747.issue45975@roundup.psfhosted.org>
In-reply-to
Content
The following pattern occurs a few times in the codebase:

  while 1:
      data = conn.recv(blocksize)
      if not data:
          break
      ...

There is an unbounded while loop in which some kind of input is read. If the input is there, it is processed and the loop is continued; otherwise the loop is broken.

This can be expressed more cleanly with the walrus operator:

  while data := conn.recv(blocksize):
     ...

Some of this code goes back to the days of Python 1. I assume that the original authors would have used the walrus idiom if it had been available, which it wasn't. But now it is.

Rewriting the instances of this pattern shaves off 148 lines from the codebase. Removing the manual break statements makes the logic more straightforward.

This should not change the behavior of anything. I'm assuming that this code is all under test and that any deviations from the existing behavior will be caught. Anything that isn't tested shouldn't be changed (and should be tested).
History
Date User Action Args
2021-12-03 23:15:50nickdrozdsetrecipients: + nickdrozd
2021-12-03 23:15:50nickdrozdsetmessageid: <1638573350.23.0.80297686747.issue45975@roundup.psfhosted.org>
2021-12-03 23:15:50nickdrozdlinkissue45975 messages
2021-12-03 23:15:50nickdrozdcreate