Skip to content

Commit df32e68

Browse files
committed
Some simplifications
1 parent 4ec5d76 commit df32e68

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

bpython/curtsiesfrontend/interpreter.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ def writetb(self, lines: Iterable[str]) -> None:
9494
# TODO for tracebacks get_lexer_by_name("pytb", stripall=True)
9595

9696
def format(self, tbtext: str, lexer: Any) -> None:
97-
# FIXME: lexer should is a Lexer
97+
# FIXME: lexer should be "Lexer"
9898
traceback_informative_formatter = BPythonFormatter(default_colors)
99-
traceback_code_formatter = BPythonFormatter({Token: ("d")})
99+
traceback_code_formatter = BPythonFormatter({Token: "d"})
100100

101101
no_format_mode = False
102102
cur_line = []
@@ -111,7 +111,7 @@ def format(self, tbtext: str, lexer: Any) -> None:
111111
cur_line, self.outfile
112112
)
113113
cur_line = []
114-
elif text == " " and cur_line == []:
114+
elif text == " " and len(cur_line) == 0:
115115
no_format_mode = True
116116
cur_line.append((token, text))
117117
else:
@@ -130,9 +130,6 @@ def code_finished_will_parse(
130130
False, True means code block is unfinished
131131
False, False isn't possible - an predicted error makes code block done"""
132132
try:
133-
finished = bool(compiler(s))
134-
code_will_parse = True
133+
return bool(compiler(s)), True
135134
except (ValueError, SyntaxError, OverflowError):
136-
finished = True
137-
code_will_parse = False
138-
return finished, code_will_parse
135+
return True, False

bpython/curtsiesfrontend/repl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,9 +1363,8 @@ def unhighlight_paren(self):
13631363
def clear_current_block(self, remove_from_history=True):
13641364
self.display_buffer = []
13651365
if remove_from_history:
1366-
for unused in self.buffer:
1367-
self.history.pop()
1368-
self.all_logical_lines.pop()
1366+
del self.history[-len(self.buffer) :]
1367+
del self.all_logical_lines[-len(self.buffer) :]
13691368
self.buffer = []
13701369
self.cursor_offset = 0
13711370
self.saved_indent = 0
@@ -2080,7 +2079,6 @@ def focus_on_subprocess(self, args):
20802079
try:
20812080
signal.signal(signal.SIGWINCH, self.orig_sigwinch_handler)
20822081
with Termmode(self.orig_stdin, self.orig_tcattrs):
2083-
assert self.window is not None
20842082
terminal = self.window.t
20852083
with terminal.fullscreen():
20862084
sys.__stdout__.write(terminal.save)

0 commit comments

Comments
 (0)