[Python-Dev] Assignment expression and coding style: the while True case (original) (raw)

Victor Stinner vstinner at redhat.com
Wed Jul 4 20:03:23 EDT 2018


On the 3360 for loops of the stdlib (*), I only found 2 loops which would benefit of assignment expressions.

It's not easy to find loops which:

diff --git a/Lib/mailbox.py b/Lib/mailbox.py index 056251dce0..dc61a3a8b6 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -1341,9 +1341,9 @@ class Babyl(_singlefileMailbox): if len(stops) < len(starts): stops.append(line_pos - len(linesep)) starts.append(next_pos)

self._file.readline()[1:].split(b',')

diff --git a/Lib/nntplib.py b/Lib/nntplib.py index 5961a28ab7..a5d13e35be 100644 --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -843,11 +843,9 @@ class _NNTPBase: DeprecationWarning, 2) line_pat = re.compile('^([^ \t]+)[ \t]+(.*)$') resp, raw_lines = self._longcmdstring('XGTITLE ' + group, file)

(*) Command used to count the number of for loops in the stdlib:

$ grep '\bfor\b' Lib/py Lib/{asyncio,logging,multiprocessing}/.py|grep -v '"""'|grep -v "'''"|grep -v '.py: *#'|wc -l 3360

Victor



More information about the Python-Dev mailing list