8000 bpo-45975: Simplify some while-loops with walrus operator by nickdrozd · Pull Request #29347 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45975: Simplify some while-loops with walrus operator #29347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert IDLE changes
  • Loading branch information
nickdrozd committed Feb 2, 2022
commit 062b0b08f77d4ff76947da5b88048e08fb0e4643
5 changes: 4 additions & 1 deletion Lib/idlelib/idle_test/test_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,10 @@ def get_shell_line_y_coords(self):
index = text.index("@0,0")
if index.split('.', 1)[1] != '0':
index = text.index(f"{index} +1line linestart")
while (lineinfo := text.dlineinfo(index)) is not None:
while True:
lineinfo = text.dlineinfo(index)
if lineinfo is None:
break
y_coords.append(lineinfo[1])
index = text.index(f"{index} +1line")
return y_coords
Expand Down
12 changes: 8 additions & 4 deletions Lib/idlelib/pyparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,14 @@ def find_good_parse_start(self, is_char_in_string):
# Peeking back worked; look forward until _synchre no longer
# matches.
i = pos + 1
while (m := _synchre(code, i)):
s, i = m.span()
if not is_char_in_string(s):
pos = s
while 1:
m = _synchre(code, i)
if m:
s, i = m.span()
if not is_char_in_string(s):
pos = s
else:
break
return pos

def set_lo(self, lo):
Expand Down
7 changes: 5 additions & 2 deletions Lib/idlelib/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ 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 (res := self.engine.search_forward(
text, prog, line, col, wrap=False, ok=ok)):
while True:
res = self.engine.search_forward(text, prog, line, col,
wrap=False, ok=ok)
if not res:
break
line, m = res
chars = text.get("%d.0" % line, "%d.0" % (line+1))
orig = m.group()
Expand Down
4 changes: 3 additions & 1 deletion Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ def read(self, size=-1):
result = self._line_buffer
self._line_buffer = ''
if size < 0:
while (line := self.shell.readline()):
while True:
line = self.shell.readline()
if not line: break
result += line
else:
while len(result) < size:
Expand Down
5 changes: 4 additions & 1 deletion Lib/idlelib/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ def update_sidebar(self):
index = text.index("@0,0")
if index.split('.', 1)[1] != '0':
index = text.index(f'{index}+1line linestart')
while (lineinfo := text.dlineinfo(index)) is not None:
while True:
lineinfo = text.dlineinfo(index)
if lineinfo is None:
break
y = lineinfo[1]
prev_newline_tagnames = text_tagnames(f"{index} linestart -1c")
prompt = (
Expand Down
0