summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2022-02-03 03:12:38 (GMT)
committerGitHub <noreply@github.com>2022-02-03 03:12:38 (GMT)
commitfafd2dadf63973a04f5693e5be19f3e7521c10d4 (patch)
tree6d5218ae9997f78b641db7424921cd1c2eb7d3e2
parent3c6173ca67c019f3eb7a2fc34c5bfc426f99c5b2 (diff)
downloadcpython-fafd2dadf63973a04f5693e5be19f3e7521c10d4.zip
cpython-fafd2dadf63973a04f5693e5be19f3e7521c10d4.tar.gz
cpython-fafd2dadf63973a04f5693e5be19f3e7521c10d4.tar.bz2
[3.9] bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
co-authored by Nick Drozd cherrypicked from 51a95be1d035a717ab29e98056b8831a98e61125
-rw-r--r--Lib/idlelib/pyparse.py12
-rw-r--r--Lib/idlelib/replace.py7
-rw-r--r--Lib/idlelib/run.py4
3 files changed, 7 insertions, 16 deletions
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 6be034a..70d761d 100644
--- a/Lib/idlelib/replace.py
+++ b/Lib/idlelib/replace.py
@@ -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()
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py
index dda9711..4246f49 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -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: