summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2022-02-03 01:59:24 (GMT)
committerGitHub <noreply@github.com>2022-02-03 01:59:24 (GMT)
commit51a95be1d035a717ab29e98056b8831a98e61125 (patch)
treee50beac085f7ae2fb5bac1104571804aa93e0053 /Lib
parent164a017e13ee96bd1ea1ae79f5ac9e25fe83994e (diff)
downloadcpython-51a95be1d035a717ab29e98056b8831a98e61125.zip
cpython-51a95be1d035a717ab29e98056b8831a98e61125.tar.gz
cpython-51a95be1d035a717ab29e98056b8831a98e61125.tar.bz2
bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/idlelib/idle_test/test_sidebar.py5
-rw-r--r--Lib/idlelib/pyparse.py12
-rw-r--r--Lib/idlelib/replace.py7
-rw-r--r--Lib/idlelib/run.py4
-rw-r--r--Lib/idlelib/sidebar.py5
5 files changed, 9 insertions, 24 deletions
diff --git a/Lib/idlelib/idle_test/test_sidebar.py b/Lib/idlelib/idle_test/test_sidebar.py
index 53ac3eb..01fd6a0 100644
--- a/Lib/idlelib/idle_test/test_sidebar.py
+++ b/Lib/idlelib/idle_test/test_sidebar.py
@@ -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
diff --git a/Lib/idlelib/pyparse.py b/Lib/idlelib/pyparse.py
index d34872b..a943275 100644
--- a/Lib/idlelib/pyparse.py
+++ b/Lib/idlelib/pyparse.py
@@ -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):
diff --git a/Lib/idlelib/replace.py b/Lib/idlelib/replace.py
index 2f9ca23..ac04ed9 100644
--- a/Lib/idlelib/replace.py
+++ b/Lib/idlelib/replace.py
@@ -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()
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index 47c4cbd..01f8d65 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -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:
diff --git a/Lib/idlelib/sidebar.py b/Lib/idlelib/sidebar.py
index 018c368..fb1084d 100644
--- a/Lib/idlelib/sidebar.py
+++ b/Lib/idlelib/sidebar.py
@@ -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 = (