mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-45975: Use walrus operator for some idlelib while loops (GH-31083)
This commit is contained in:
parent
164a017e13
commit
51a95be1d0
5 changed files with 9 additions and 24 deletions
|
@ -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
|
||||||
|
|
|
@ -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)
|
|
||||||
if m:
|
|
||||||
s, i = m.span()
|
s, i = m.span()
|
||||||
if not is_char_in_string(s):
|
if not is_char_in_string(s):
|
||||||
pos = s
|
pos = s
|
||||||
else:
|
|
||||||
break
|
|
||||||
return pos
|
return pos
|
||||||
|
|
||||||
def set_lo(self, lo):
|
def set_lo(self, lo):
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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 = (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue