5252import struct
5353import sys
5454import time
55- from typing import Iterator , NoReturn , List , MutableMapping , Any , Callable , TypeVar , cast , IO , Iterable , Optional
55+ from typing import Iterator , NoReturn , List , MutableMapping , Any , Callable , TypeVar , cast , IO , Iterable , Optional , Union , Tuple
5656import unicodedata
5757from dataclasses import dataclass
5858
@@ -330,7 +330,7 @@ def confirm(self, q: str) -> bool:
330330 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 : int ) -> str :
333+ def file_prompt (self , s : str ) -> str :
334334 return self .statusbar .prompt (s )
335335
336336
@@ -668,7 +668,7 @@ def get_key(self) -> str:
668668 if self .idle :
669669 self .idle (self )
670670
671- def get_line (self ) -> Optional [ str ] :
671+ def get_line (self ) -> str :
672672 """Get a line of text and return it
673673 This function initialises an empty string and gets the
674674 curses cursor position on the screen and stores it
@@ -694,14 +694,14 @@ def get_line(self) -> Optional[str]:
694694 self .s = self .s [4 :]
695695 return self .s
696696
697- def home (self , refresh = True ):
697+ def home (self , refresh : bool = True ) -> bool :
698698 self .scr .move (self .iy , self .ix )
699699 self .cpos = len (self .s )
700700 if refresh :
701701 self .scr .refresh ()
702702 return True
703703
704- def lf (self ):
704+ def lf (self ) -> None :
705705 """Process a linefeed character; it only needs to check the
706706 cursor position and move appropriately so it doesn't clear
707707 the current line after the cursor."""
@@ -713,7 +713,12 @@ def lf(self):
713713 self .print_line (self .s , newline = True )
714714 self .echo ("\n " )
715715
716- def mkargspec (self , topline , in_arg , down ):
716+ def mkargspec (
717+ self ,
718+ topline : Any , # Named tuples don't seem to play nice with mypy
719+ in_arg : Union [str , int ],
720+ down : bool
721+ ) -> int :
717722 """This figures out what to do with the argspec and puts it nicely into
718723 the list window. It returns the number of lines used to display the
719724 argspec. It's also kind of messy due to it having to call so many
@@ -817,7 +822,7 @@ def mkargspec(self, topline, in_arg, down):
817822
818823 return r
819824
820- def mvc (self , i , refresh = True ):
825+ def mvc (self , i : int , refresh : bool = True ) -> bool :
821826 """This method moves the cursor relatively from the current
822827 position, where:
823828 0 == (right) end of current line
@@ -850,7 +855,7 @@ def mvc(self, i, refresh=True):
850855
851856 return True
852857
853- def p_key (self , key ) :
858+ def p_key (self , key : str ) -> Union [ None , str , bool ] :
854859 """Process a keypress"""
855860
856861 if key is None :
@@ -1044,7 +1049,7 @@ def p_key(self, key):
10441049
10451050 return True
10461051
1047- def print_line (self , s , clr = False , newline = False ):
1052+ def print_line (self , s : Optional [ str ] , clr : bool = False , newline : bool = False ) -> None :
10481053 """Chuck a line of text through the highlighter, move the cursor
10491054 to the beginning of the line and output it to the screen."""
10501055
@@ -1080,7 +1085,10 @@ def print_line(self, s, clr=False, newline=False):
10801085 self .mvc (1 )
10811086 self .cpos = t
10821087
1083- def prompt (self , more ):
1088+ def prompt (
1089+ self ,
1090+ more : Any # I'm not sure of the type on this one
1091+ ) -> None :
10841092 """Show the appropriate Python prompt"""
10851093 if not more :
10861094 self .echo (
@@ -1101,7 +1109,7 @@ def prompt(self, more):
11011109 f"\x01 { prompt_more_color } \x03 { self .ps2 } \x04 "
11021110 )
11031111
1104- def push (self , s , insert_into_history = True ):
1112+ def push (self , s : str , insert_into_history : bool = True ) -> bool :
11051113 # curses.raw(True) prevents C-c from causing a SIGINT
11061114 curses .raw (False )
11071115 try :
@@ -1114,7 +1122,7 @@ def push(self, s, insert_into_history=True):
11141122 finally :
11151123 curses .raw (True )
11161124
1117- def redraw (self ):
1125+ def redraw (self ) -> None :
11181126 """Redraw the screen using screen_hist"""
11191127 self .scr .erase ()
11201128 for k , s in enumerate (self .screen_hist ):
@@ -1130,7 +1138,7 @@ def redraw(self):
11301138 self .scr .refresh ()
11311139 self .statusbar .refresh ()
11321140
1133- def repl (self ):
1141+ def repl (self ) -> Tuple :
11341142 """Initialise the repl and jump into the loop. This method also has to
11351143 keep a stack of lines entered for the horrible "undo" feature. It also
11361144 tracks everything that would normally go to stdout in the normal Python
@@ -1171,7 +1179,7 @@ def repl(self):
11711179 self .s = ""
11721180 return self .exit_value
11731181
1174- def reprint_line (self , lineno , tokens ) :
1182+ def reprint_line (self , lineno : int , tokens : MutableMapping [ _TokenType , str ]) -> None :
11751183 """Helper function for paren highlighting: Reprint line at offset
11761184 `lineno` in current input buffer."""
11771185 if not self .buffer or lineno == len (self .buffer ):
@@ -1194,7 +1202,7 @@ def reprint_line(self, lineno, tokens):
11941202 for string in line .split ("\x04 " ):
11951203 self .echo (string )
11961204
1197- def resize (self ):
1205+ def resize (self ) -> None :
11981206 """This method exists simply to keep it straight forward when
11991207 initialising a window and resizing it."""
12001208 self .size ()
@@ -1204,13 +1212,13 @@ def resize(self):
12041212 self .statusbar .resize (refresh = False )
12051213 self .redraw ()
12061214
1207- def getstdout (self ):
1215+ def getstdout (self ) -> str :
12081216 """This method returns the 'spoofed' stdout buffer, for writing to a
12091217 file or sending to a pastebin or whatever."""
12101218
12111219 return self .stdout_hist + "\n "
12121220
1213- def reevaluate (self ):
1221+ def reevaluate (self ) -> None :
12141222 """Clear the buffer, redraw the screen and re-evaluate the history"""
12151223
12161224 self .evaluating = True
@@ -1249,7 +1257,7 @@ def reevaluate(self):
12491257 # map(self.push, self.history)
12501258 # ^-- That's how simple this method was at first :(
12511259
1252- def write (self , s ) :
1260+ def write (self , s : str ) -> None :
12531261 """For overriding stdout defaults"""
12541262 if "\x04 " in s :
12551263 for block in s .split ("\x04 " ):
@@ -1418,7 +1426,7 @@ def suspend(self):
14181426 curses .endwin ()
14191427 os .kill (os .getpid (), signal .SIGSTOP )
14201428
1421- def tab (self , back = False ):
1429+ def tab (self , back : bool = False ) -> bool :
14221430 """Process the tab key being hit.
14231431
14241432 If there's only whitespace
@@ -1498,7 +1506,7 @@ def yank_from_buffer(self):
14981506 self .addstr (self .cut_buffer )
14991507 self .print_line (self .s , clr = True )
15001508
1501- def send_current_line_to_editor (self ):
1509+ def send_current_line_to_editor (self ) -> str :
15021510 lines = self .send_to_external_editor (self .s ).split ("\n " )
15031511 self .s = ""
15041512 self .print_line (self .s )
0 commit comments