Skip to content

Commit 752d684

Browse files
committed
Less list comprehensions
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 8a7e5d4 commit 752d684

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,8 @@ def unhighlight_paren(self):
907907
def clear_current_block(self, remove_from_history=True):
908908
self.display_buffer = []
909909
if remove_from_history:
910-
[self.history.pop() for _ in self.buffer]
910+
for _ in self.buffer:
911+
self.history.pop()
911912
self.buffer = []
912913
self.cursor_offset = 0
913914
self.saved_indent = 0
@@ -923,15 +924,19 @@ def send_to_stdout(self, output):
923924
self.current_stdouterr_line += lines[0]
924925
if len(lines) > 1:
925926
self.display_lines.extend(paint.display_linize(self.current_stdouterr_line, self.width, blank_line=True))
926-
self.display_lines.extend(sum([paint.display_linize(line, self.width, blank_line=True) for line in lines[1:-1]], []))
927+
self.display_lines.extend(sum((paint.display_linize(line, self.width,
928+
blank_line=True)
929+
for line in lines[1:-1]), []))
927930
self.current_stdouterr_line = lines[-1]
928931
logger.debug('display_lines: %r', self.display_lines)
929932

930933
def send_to_stderr(self, error):
931934
lines = error.split('\n')
932935
if lines[-1]:
933936
self.current_stdouterr_line += lines[-1]
934-
self.display_lines.extend(sum([paint.display_linize(line, self.width, blank_line=True) for line in lines[:-1]], []))
937+
self.display_lines.extend(sum((paint.display_linize(line, self.width,
938+
blank_line=True) for
939+
line in lines[:-1]), []))
935940

936941
def send_to_stdin(self, line):
937942
if line.endswith('\n'):
@@ -1017,8 +1022,11 @@ def current_cursor_line(self):
10171022

10181023
@property
10191024
def current_suggestion(self):
1020-
matches = [e for e in self.rl_history.entries if e.startswith(self.current_line) and self.current_line]
1021-
return matches[-1][len(self.current_line):] if matches else ''
1025+
if self.current_line:
1026+
for entry in reversed(self.rl_history.entries):
1027+
if entry.startswith(self.current_line):
1028+
return entry[len(self.current_line):]
1029+
return ''
10221030

10231031
@property
10241032
def current_output_line(self):
@@ -1349,8 +1357,8 @@ def reevaluate(self, insert_into_history=False):
13491357
num_lines_onscreen = len(self.lines_for_display) - max(0, self.scroll_offset)
13501358
display_lines_offscreen = self.display_lines[:len(self.display_lines) - num_lines_onscreen]
13511359
old_display_lines_offscreen = old_display_lines[:len(self.display_lines) - num_lines_onscreen]
1352-
logger.debug('old_display_lines_offscreen %s', '|'.join([str(x) for x in old_display_lines_offscreen]))
1353-
logger.debug(' display_lines_offscreen %s', '|'.join([str(x) for x in display_lines_offscreen]))
1360+
logger.debug('old_display_lines_offscreen %s', '|'.join(str(x) for x in old_display_lines_offscreen))
1361+
logger.debug(' display_lines_offscreen %s', '|'.join(str(x) for x in display_lines_offscreen))
13541362
if old_display_lines_offscreen[:len(display_lines_offscreen)] != display_lines_offscreen and not self.history_already_messed_up:
13551363
#self.scroll_offset = self.scroll_offset + (len(old_display_lines)-len(self.display_lines))
13561364
self.inconsistent_history = True
@@ -1361,8 +1369,8 @@ def reevaluate(self, insert_into_history=False):
13611369

13621370
def getstdout(self):
13631371
lines = self.lines_for_display + [self.current_line_formatted]
1364-
s = '\n'.join([x.s if isinstance(x, FmtStr) else x for x in lines]
1365-
) if lines else ''
1372+
s = '\n'.join(x.s if isinstance(x, FmtStr) else x for x in lines) \
1373+
if lines else ''
13661374
return s
13671375

13681376
def focus_on_subprocess(self, args):

bpython/curtsiesfrontend/replpainter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
23
import logging
34

45
from curtsies import fsarray, fmtstr
@@ -175,7 +176,7 @@ def add_border(line):
175176
def paint_last_events(rows, columns, names, config):
176177
if not names:
177178
return fsarray([])
178-
width = min(max([len(name) for name in names] + [0]), columns-2)
179+
width = min(max(len(name) for name in names), columns-2)
179180
output_lines = []
180181
output_lines.append(config.left_top_corner+config.top_border*(width)+config.right_top_corner)
181182
for name in reversed(names[max(0, len(names)-(rows-2)):]):

0 commit comments

Comments
 (0)