[Python-checkins] [3.9] bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
terryjreedy
webhook-mailer at python.org
Wed Feb 2 22:12:48 EST 2022
https://github.com/python/cpython/commit/fafd2dadf63973a04f5693e5be19f3e7521c10d4
commit: fafd2dadf63973a04f5693e5be19f3e7521c10d4
branch: 3.9
author: Terry Jan Reedy <tjreedy at udel.edu>
committer: terryjreedy <tjreedy at udel.edu>
date: 2022-02-02T22:12:38-05:00
summary:
[3.9] bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
co-authored by Nick Drozd
cherrypicked from 51a95be1d035a717ab29e98056b8831a98e61125
files:
M Lib/idlelib/pyparse.py
M Lib/idlelib/replace.py
M Lib/idlelib/run.py
diff --git a/Lib/idlelib/pyparse.py b/Lib/idlelib/pyparse.py
index d34872b4396e1..a94327533d865 100644
--- a/Lib/idlelib/pyparse.py
+++ b/Lib/idlelib/pyparse.py
@@ -179,14 +179,10 @@ def find_good_parse_start(self, is_char_in_string):
# 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 6be034af9626b..70d761db12630 100644
--- a/Lib/idlelib/replace.py
+++ b/Lib/idlelib/replace.py
@@ -156,11 +156,8 @@ def replace_all(self, event=None):
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 dda9711dcf7ae..4246f497cb382 100644
--- a/Lib/idlelib/run.py
+++ b/Lib/idlelib/run.py
@@ -468,9 +468,7 @@ def read(self, size=-1):
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:
More information about the Python-checkins
mailing list