]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.9] bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
authorTerry Jan Reedy <tjreedy@udel.edu>
Thu, 3 Feb 2022 03:12:38 +0000 (22:12 -0500)
committerGitHub <noreply@github.com>
Thu, 3 Feb 2022 03:12:38 +0000 (22:12 -0500)
co-authored by Nick Drozd
cherrypicked from 51a95be1d035a717ab29e98056b8831a98e61125

Lib/idlelib/pyparse.py
Lib/idlelib/replace.py
Lib/idlelib/run.py

index d34872b4396e1e2abdc399de1a9e91e76ceadd35..a94327533d865abb8e665cf14dc252b40028f6f4 100644 (file)
@@ -179,14 +179,10 @@ class Parser:
         # Peeking back worked; look forward until _synchre no longer
         # matches.
         i = pos + 1
-        while 1:
-            m = _synchre(code, i)
-            if m:
-                s, i = m.span()
-                if not is_char_in_string(s):
-                    pos = s
-            else:
-                break
+        while (m := _synchre(code, i)):
+            s, i = m.span()
+            if not is_char_in_string(s):
+                pos = s
         return pos
 
     def set_lo(self, lo):
index 6be034af9626b30a7d7b54085fb651b24183aad3..70d761db126308ed4809c26be4bbc02ca6bc0949 100644 (file)
@@ -156,11 +156,8 @@ class ReplaceDialog(SearchDialogBase):
         first = last = None
         # XXX ought to replace circular instead of top-to-bottom when wrapping
         text.undo_block_start()
-        while True:
-            res = self.engine.search_forward(text, prog, line, col,
-                                             wrap=False, ok=ok)
-            if not res:
-                break
+        while (res := self.engine.search_forward(
+                text, prog, line, col, wrap=False, ok=ok)):
             line, m = res
             chars = text.get("%d.0" % line, "%d.0" % (line+1))
             orig = m.group()
index dda9711dcf7aed859656b5b67887e4541b18494f..4246f497cb382b6047f49897c745ff1b2ad73cc5 100644 (file)
@@ -468,9 +468,7 @@ class StdInputFile(StdioFile):
         result = self._line_buffer
         self._line_buffer = ''
         if size < 0:
-            while True:
-                line = self.shell.readline()
-                if not line: break
+            while (line := self.shell.readline()):
                 result += line
         else:
             while len(result) < size: