bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)

This commit is contained in:
Nick Drozd 2022-02-02 19:59:24 -06:00 committed by GitHub
parent 164a017e13
commit 51a95be1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 24 deletions

View 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

View 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):

View 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()

View 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:

View 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 = (