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") index = text.index("@0,0")
if index.split('.', 1)[1] != '0': if index.split('.', 1)[1] != '0':
index = text.index(f"{index} +1line linestart") index = text.index(f"{index} +1line linestart")
while True: while (lineinfo := text.dlineinfo(index)) is not None:
lineinfo = text.dlineinfo(index)
if lineinfo is None:
break
y_coords.append(lineinfo[1]) y_coords.append(lineinfo[1])
index = text.index(f"{index} +1line") index = text.index(f"{index} +1line")
return y_coords return y_coords

View file

@ -179,14 +179,10 @@ class Parser:
# Peeking back worked; look forward until _synchre no longer # Peeking back worked; look forward until _synchre no longer
# matches. # matches.
i = pos + 1 i = pos + 1
while 1: while (m := _synchre(code, i)):
m = _synchre(code, i) s, i = m.span()
if m: if not is_char_in_string(s):
s, i = m.span() pos = s
if not is_char_in_string(s):
pos = s
else:
break
return pos return pos
def set_lo(self, lo): def set_lo(self, lo):

View file

@ -158,11 +158,8 @@ class ReplaceDialog(SearchDialogBase):
first = last = None first = last = None
# XXX ought to replace circular instead of top-to-bottom when wrapping # XXX ought to replace circular instead of top-to-bottom when wrapping
text.undo_block_start() text.undo_block_start()
while True: while (res := self.engine.search_forward(
res = self.engine.search_forward(text, prog, line, col, text, prog, line, col, wrap=False, ok=ok)):
wrap=False, ok=ok)
if not res:
break
line, m = res line, m = res
chars = text.get("%d.0" % line, "%d.0" % (line+1)) chars = text.get("%d.0" % line, "%d.0" % (line+1))
orig = m.group() orig = m.group()

View file

@ -482,9 +482,7 @@ class StdInputFile(StdioFile):
result = self._line_buffer result = self._line_buffer
self._line_buffer = '' self._line_buffer = ''
if size < 0: if size < 0:
while True: while (line := self.shell.readline()):
line = self.shell.readline()
if not line: break
result += line result += line
else: else:
while len(result) < size: while len(result) < size:

View file

@ -471,10 +471,7 @@ class ShellSidebar(BaseSideBar):
index = text.index("@0,0") index = text.index("@0,0")
if index.split('.', 1)[1] != '0': if index.split('.', 1)[1] != '0':
index = text.index(f'{index}+1line linestart') index = text.index(f'{index}+1line linestart')
while True: while (lineinfo := text.dlineinfo(index)) is not None:
lineinfo = text.dlineinfo(index)
if lineinfo is None:
break
y = lineinfo[1] y = lineinfo[1]
prev_newline_tagnames = text_tagnames(f"{index} linestart -1c") prev_newline_tagnames = text_tagnames(f"{index} linestart -1c")
prompt = ( prompt = (