Skip to content

Commit 3c3a81d

Browse files
Ben-Regsebastinas
authored andcommitted
Still working my way down.
1 parent 9c56f05 commit 3c3a81d

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

bpython/cli.py

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

316316

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

321-
def confirm(self, q):
321+
def confirm(self, q: str) -> bool:
322322
"""Ask for yes or no and return boolean"""
323323
try:
324324
reply = self.statusbar.prompt(q)
@@ -327,15 +327,15 @@ def confirm(self, q):
327327

328328
return reply.lower() in (_("y"), _("yes"))
329329

330-
def notify(self, s, n=10, wait_for_keypress=False):
330+
def notify(self, s: str, n: int = 10, wait_for_keypress: bool = False) -> None:
331331
return self.statusbar.message(s, n)
332332

333-
def file_prompt(self, s):
333+
def file_prompt(self, s: int) -> str:
334334
return self.statusbar.prompt(s)
335335

336336

337337
class CLIRepl(repl.Repl):
338-
def __init__(self, scr, interp, statusbar, config, idle=None):
338+
def __init__(self, scr: curses.window, interp: repl.Interpreter, statusbar: 'Statusbar', config: Config, idle: None = None):
339339
super().__init__(interp, config)
340340
self.interp.writetb = self.writetb
341341
self.scr = scr
@@ -357,10 +357,10 @@ def __init__(self, scr, interp, statusbar, config, idle=None):
357357
if config.cli_suggestion_width <= 0 or config.cli_suggestion_width > 1:
358358
config.cli_suggestion_width = 0.8
359359

360-
def _get_cursor_offset(self):
360+
def _get_cursor_offset(self) -> int:
361361
return len(self.s) - self.cpos
362362

363-
def _set_cursor_offset(self, offset):
363+
def _set_cursor_offset(self, offset: int) -> None:
364364
self.cpos = len(self.s) - offset
365365

366366
cursor_offset = property(
@@ -370,7 +370,7 @@ def _set_cursor_offset(self, offset):
370370
"The cursor offset from the beginning of the line",
371371
)
372372

373-
def addstr(self, s):
373+
def addstr(self, s: str) -> None:
374374
"""Add a string to the current input line and figure out
375375
where it should go, depending on the cursor position."""
376376
self.rl_history.reset()
@@ -382,7 +382,7 @@ def addstr(self, s):
382382

383383
self.complete()
384384

385-
def atbol(self):
385+
def atbol(self) -> bool:
386386
"""Return True or False accordingly if the cursor is at the beginning
387387
of the line (whitespace is ignored). This exists so that p_key() knows
388388
how to handle the tab key being pressed - if there is nothing but white
@@ -391,17 +391,18 @@ def atbol(self):
391391

392392
return not self.s.lstrip()
393393

394-
def bs(self, delete_tabs=True):
394+
# This function shouldn't return None because of pos -= self.bs() later on
395+
def bs(self, delete_tabs: bool = True) -> int: # type: ignore[return-value]
395396
"""Process a backspace"""
396397

397398
self.rl_history.reset()
398399
y, x = self.scr.getyx()
399400

400401
if not self.s:
401-
return
402+
return None # type: ignore[return-value]
402403

403404
if x == self.ix and y == self.iy:
404-
return
405+
return None # type: ignore[return-value]
405406

406407
n = 1
407408

@@ -422,7 +423,7 @@ def bs(self, delete_tabs=True):
422423

423424
return n
424425

425-
def bs_word(self):
426+
def bs_word(self) -> str:
426427
self.rl_history.reset()
427428
pos = len(self.s) - self.cpos - 1
428429
deleted = []
@@ -437,7 +438,7 @@ def bs_word(self):
437438

438439
return "".join(reversed(deleted))
439440

440-
def check(self):
441+
def check(self) -> None:
441442
"""Check if paste mode should still be active and, if not, deactivate
442443
it and force syntax highlighting."""
443444

@@ -448,14 +449,14 @@ def check(self):
448449
self.paste_mode = False
449450
self.print_line(self.s)
450451

451-
def clear_current_line(self):
452+
def clear_current_line(self) -> None:
452453
"""Called when a SyntaxError occurred in the interpreter. It is
453454
used to prevent autoindentation from occurring after a
454455
traceback."""
455456
repl.Repl.clear_current_line(self)
456457
self.s = ""
457458

458-
def clear_wrapped_lines(self):
459+
def clear_wrapped_lines(self) -> None:
459460
"""Clear the wrapped lines of the current input."""
460461
# curses does not handle this on its own. Sad.
461462
height, width = self.scr.getmaxyx()
@@ -464,7 +465,7 @@ def clear_wrapped_lines(self):
464465
self.scr.move(y, 0)
465466
self.scr.clrtoeol()
466467

467-
def complete(self, tab=False):
468+
def complete(self, tab: bool = False) -> None:
468469
"""Get Autocomplete list and window.
469470
470471
Called whenever these should be updated, and called
@@ -494,7 +495,7 @@ def complete(self, tab=False):
494495
self.scr.redrawwin()
495496
self.scr.refresh()
496497

497-
def clrtobol(self):
498+
def clrtobol(self) -> None:
498499
"""Clear from cursor to beginning of line; usual C-u behaviour"""
499500
self.clear_wrapped_lines()
500501

@@ -507,10 +508,10 @@ def clrtobol(self):
507508
self.scr.redrawwin()
508509
self.scr.refresh()
509510

510-
def _get_current_line(self):
511+
def _get_current_line(self) -> str:
511512
return self.s
512513

513-
def _set_current_line(self, line):
514+
def _set_current_line(self, line: str) -> None:
514515
self.s = line
515516

516517
current_line = property(
@@ -520,7 +521,7 @@ def _set_current_line(self, line):
520521
"The characters of the current line",
521522
)
522523

523-
def cut_to_buffer(self):
524+
def cut_to_buffer(self) -> None:
524525
"""Clear from cursor to end of line, placing into cut buffer"""
525526
self.cut_buffer = self.s[-self.cpos :]
526527
self.s = self.s[: -self.cpos]
@@ -529,15 +530,15 @@ def cut_to_buffer(self):
529530
self.scr.redrawwin()
530531
self.scr.refresh()
531532

532-
def delete(self):
533+
def delete(self) -> None:
533534
"""Process a del"""
534535
if not self.s:
535536
return
536537

537538
if self.mvc(-1):
538539
self.bs(False)
539540

540-
def echo(self, s, redraw=True):
541+
def echo(self, s: str, redraw: bool = True) -> None:
541542
"""Parse and echo a formatted string with appropriate attributes. It
542543
uses the formatting method as defined in formatter.py to parse the
543544
strings. It won't update the screen if it's reevaluating the code (as it
@@ -571,7 +572,7 @@ def echo(self, s, redraw=True):
571572
if redraw and not self.evaluating:
572573
self.scr.refresh()
573574

574-
def end(self, refresh=True):
575+
def end(self, refresh: bool = True) -> bool:
575576
self.cpos = 0
576577
h, w = gethw()
577578
y, x = divmod(len(self.s) + self.ix, w)
@@ -582,7 +583,7 @@ def end(self, refresh=True):
582583

583584
return True
584585

585-
def hbegin(self):
586+
def hbegin(self) -> None:
586587
"""Replace the active line with first line in history and
587588
increment the index to keep track"""
588589
self.cpos = 0
@@ -591,15 +592,15 @@ def hbegin(self):
591592
self.s = self.rl_history.first()
592593
self.print_line(self.s, clr=True)
593594

594-
def hend(self):
595+
def hend(self) -> None:
595596
"""Same as hbegin() but, well, forward"""
596597
self.cpos = 0
597598
self.clear_wrapped_lines()
598599
self.rl_history.enter(self.s)
599600
self.s = self.rl_history.last()
600601
self.print_line(self.s, clr=True)
601602

602-
def back(self):
603+
def back(self) -> None:
603604
"""Replace the active line with previous line in history and
604605
increment the index to keep track"""
605606

@@ -609,7 +610,7 @@ def back(self):
609610
self.s = self.rl_history.back()
610611
self.print_line(self.s, clr=True)
611612

612-
def fwd(self):
613+
def fwd(self) -> None:
613614
"""Same as back() but, well, forward"""
614615

615616
self.cpos = 0
@@ -618,7 +619,7 @@ def fwd(self):
618619
self.s = self.rl_history.forward()
619620
self.print_line(self.s, clr=True)
620621

621-
def search(self):
622+
def search(self) -> None:
622623
"""Search with the partial matches from the history object."""
623624

624625
self.cpo = 0
@@ -627,7 +628,7 @@ def search(self):
627628
self.s = self.rl_history.back(start=False, search=True)
628629
self.print_line(self.s, clr=True)
629630

630-
def get_key(self):
631+
def get_key(self) -> str:
631632
key = ""
632633
while True:
633634
try:
@@ -667,7 +668,7 @@ def get_key(self):
667668
if self.idle:
668669
self.idle(self)
669670

670-
def get_line(self):
671+
def get_line(self) -> Optional[str]:
671672
"""Get a line of text and return it
672673
This function initialises an empty string and gets the
673674
curses cursor position on the screen and stores it

0 commit comments

Comments
 (0)