]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
authorNick Drozd <nicholasdrozd@gmail.com>
Thu, 3 Feb 2022 01:59:24 +0000 (19:59 -0600)
committerGitHub <noreply@github.com>
Thu, 3 Feb 2022 01:59:24 +0000 (20:59 -0500)
Lib/idlelib/idle_test/test_sidebar.py
Lib/idlelib/pyparse.py
Lib/idlelib/replace.py
Lib/idlelib/run.py
Lib/idlelib/sidebar.py

index 53ac3eb27335d7a2c62f0135575ab216bf0b90fb..01fd6a04d0de3021c235ace8efd7293ea4a8f4b4 100644 (file)
@@ -474,10 +474,7 @@ class ShellSidebarTest(unittest.TestCase):
         index = text.index("@0,0")
         if index.split('.', 1)[1] != '0':
             index = text.index(f"{index} +1line linestart")
-        while True:
-            lineinfo = text.dlineinfo(index)
-            if lineinfo is None:
-                break
+        while (lineinfo := text.dlineinfo(index)) is not None:
             y_coords.append(lineinfo[1])
             index = text.index(f"{index} +1line")
         return y_coords
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 2f9ca231a05e49510c699695a3b5b4bc6b9c63e2..ac04ed94dd475336f51a1423ac0fdf225011c07a 100644 (file)
@@ -158,11 +158,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 47c4cbdcb8c3f9e2200b278a878ca78358331e9a..01f8d65426abc7fd4ec2ae5f527c40508bbca6da 100644 (file)
@@ -482,9 +482,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:
index 018c368f421c6c751c894cdf78b117b127ba4ff6..fb1084dbf3f18b6a9720e13afcd7f414fa414947 100644 (file)
@@ -471,10 +471,7 @@ class ShellSidebar(BaseSideBar):
         index = text.index("@0,0")
         if index.split('.', 1)[1] != '0':
             index = text.index(f'{index}+1line linestart')
-        while True:
-            lineinfo = text.dlineinfo(index)
-            if lineinfo is None:
-                break
+        while (lineinfo := text.dlineinfo(index)) is not None:
             y = lineinfo[1]
             prev_newline_tagnames = text_tagnames(f"{index} linestart -1c")
             prompt = (