Skip to content

Commit 4e55dde

Browse files
Ben-Regsebastinas
authored andcommitted
Finished squashing the mypy errors, use --follow-imports=error to ignore errors from imports that haven't been typed yet.
1 parent b47b918 commit 4e55dde

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

bpython/cli.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,29 @@ def make_colors(config: Config) -> MutableMapping[str, int]:
315315

316316

317317
class CLIInteraction(repl.Interaction):
318-
def __init__(self, config: Config, statusbar: 'Statusbar' = None):
318+
def __init__(self, config: Config, statusbar: Optional['Statusbar'] = None):
319319
super().__init__(config, statusbar)
320320

321321
def confirm(self, q: str) -> bool:
322322
"""Ask for yes or no and return boolean"""
323323
try:
324-
reply = self.statusbar.prompt(q)
324+
if self.statusbar:
325+
reply = self.statusbar.prompt(q)
325326
except ValueError:
326327
return False
327328

328329
return reply.lower() in (_("y"), _("yes"))
329330

330331
def notify(self, s: str, n: int = 10, wait_for_keypress: bool = False) -> None:
331-
return self.statusbar.message(s, n)
332+
if self.statusbar:
333+
self.statusbar.message(s, n)
332334

333-
def file_prompt(self, s: str) -> str:
334-
return self.statusbar.prompt(s)
335+
def file_prompt(self, s: str) -> Optional[str]:
336+
if self.statusbar:
337+
# This thows a mypy error because repl.py isn't typed yet
338+
return self.statusbar.prompt(s) # type:ignore[no-any-return]
339+
else:
340+
return None
335341

336342

337343
class CLIRepl(repl.Repl):
@@ -970,7 +976,7 @@ def p_key(self, key: str) -> Union[None, str, bool]:
970976

971977
elif key in key_dispatch[config.clear_screen_key]:
972978
# clear all but current line
973-
self.screen_hist = [self.screen_hist[-1]]
979+
self.screen_hist: List = [self.screen_hist[-1]]
974980
self.highlighted_paren = None
975981
self.redraw()
976982
return ""
@@ -1120,7 +1126,8 @@ def push(self, s: str, insert_into_history: bool = True) -> bool:
11201126
# curses.raw(True) prevents C-c from causing a SIGINT
11211127
curses.raw(False)
11221128
try:
1123-
return repl.Repl.push(self, s, insert_into_history)
1129+
x: bool = repl.Repl.push(self, s, insert_into_history)
1130+
return x
11241131
except SystemExit as e:
11251132
# Avoid a traceback on e.g. quit()
11261133
self.do_exit = True
@@ -1231,7 +1238,7 @@ def reevaluate(self) -> None:
12311238
self.evaluating = True
12321239
self.stdout_hist = ""
12331240
self.f_string = ""
1234-
self.buffer = []
1241+
self.buffer: List[str] = []
12351242
self.scr.erase()
12361243
self.screen_hist = []
12371244
# Set cursor position to -1 to prevent paren matching
@@ -1593,7 +1600,7 @@ def __init__(
15931600
):
15941601
"""Initialise the statusbar and display the initial text (if any)"""
15951602
self.size()
1596-
self.win = newwin(background, self.h, self.w, self.y, self.x)
1603+
self.win: curses.window = newwin(background, self.h, self.w, self.y, self.x)
15971604

15981605
self.config = config
15991606

@@ -1908,7 +1915,14 @@ def curses_wrapper(func: Callable, *args: Any, **kwargs: Any) -> Any:
19081915
curses.endwin()
19091916

19101917

1911-
def main_curses(scr, args, config, interactive=True, locals_=None, banner=None):
1918+
def main_curses(
1919+
scr: curses.window,
1920+
args: List[str],
1921+
config: Config,
1922+
interactive: bool = True,
1923+
locals_: Optional[MutableMapping[str, str]] = None,
1924+
banner: Optional[str] = None
1925+
) -> Tuple[Tuple[Any, ...], str]:
19121926
"""main function for the curses convenience wrapper
19131927
19141928
Initialise the two main objects: the interpreter
@@ -1941,7 +1955,9 @@ def main_curses(scr, args, config, interactive=True, locals_=None, banner=None):
19411955
curses.use_default_colors()
19421956
cols = make_colors(config)
19431957
except curses.error:
1944-
cols = FakeDict(-1)
1958+
# Not sure what to do with the types here...
1959+
# FakeDict acts as a dictionary, but isn't actually a dictionary
1960+
cols = FakeDict(-1) # type:ignore[assignment]
19451961

19461962
# FIXME: Gargh, bad design results in using globals without a refactor :(
19471963
colors = cols
@@ -1956,12 +1972,13 @@ def main_curses(scr, args, config, interactive=True, locals_=None, banner=None):
19561972
clirepl = CLIRepl(main_win, interpreter, statusbar, config, idle)
19571973
clirepl._C = cols
19581974

1959-
sys.stdin = FakeStdin(clirepl)
1960-
sys.stdout = FakeStream(clirepl, lambda: sys.stdout)
1961-
sys.stderr = FakeStream(clirepl, lambda: sys.stderr)
1975+
# Not sure how to type these Fake types
1976+
sys.stdin = FakeStdin(clirepl) # type:ignore[assignment]
1977+
sys.stdout = FakeStream(clirepl, lambda: sys.stdout) # type:ignore
1978+
sys.stderr = FakeStream(clirepl, lambda: sys.stderr) # type:ignore
19621979

19631980
if args:
1964-
exit_value = ()
1981+
exit_value: Tuple[Any, ...] = ()
19651982
try:
19661983
bpargs.exec_code(interpreter, args)
19671984
except SystemExit as e:
@@ -1995,7 +2012,8 @@ def main_curses(scr, args, config, interactive=True, locals_=None, banner=None):
19952012

19962013
exit_value = clirepl.repl()
19972014
if hasattr(sys, "exitfunc"):
1998-
sys.exitfunc()
2015+
# Seems like the if statment should satisfy mypy, but it doesn't
2016+
sys.exitfunc() # type:ignore[attr-defined]
19992017
delattr(sys, "exitfunc")
20002018

20012019
main_win.erase()
@@ -2012,7 +2030,11 @@ def main_curses(scr, args, config, interactive=True, locals_=None, banner=None):
20122030
return (exit_value, clirepl.getstdout())
20132031

20142032

2015-
def main(args=None, locals_=None, banner=None):
2033+
def main(
2034+
args: Optional[List[str]] = None,
2035+
locals_: Optional[MutableMapping[str, str]] = None,
2036+
banner: Optional[str] = None
2037+
) -> Any:
20162038
translations.init()
20172039

20182040
config, options, exec_args = argsparse(args)

0 commit comments

Comments
 (0)