5252import struct
5353import sys
5454import time
55- from typing import Iterator , NoReturn , List , MutableMapping , Any , Callable , TypeVar , cast , IO , Iterable , Optional , Union , Tuple
55+ from typing import (
56+ Iterator ,
57+ NoReturn ,
58+ List ,
59+ MutableMapping ,
60+ Any ,
61+ Callable ,
62+ TypeVar ,
63+ cast ,
64+ IO ,
65+ Iterable ,
66+ Optional ,
67+ Union ,
68+ Tuple ,
69+ )
5670import unicodedata
5771from dataclasses import dataclass
5872
8498from .pager import page
8599from .args import parse as argsparse
86100
87- F = TypeVar ('F' , bound = Callable [..., Any ])
101+ F = TypeVar ("F" , bound = Callable [..., Any ])
88102
89103# --- module globals ---
90104stdscr = None
@@ -135,7 +149,7 @@ class FakeStream:
135149 """Provide a fake file object which calls functions on the interface
136150 provided."""
137151
138- def __init__ (self , interface : ' CLIRepl' , get_dest : IO [str ]) -> None :
152+ def __init__ (self , interface : " CLIRepl" , get_dest : IO [str ]) -> None :
139153 self .encoding : str = getpreferredencoding ()
140154 self .interface = interface
141155 self .get_dest = get_dest
@@ -160,7 +174,7 @@ def flush(self) -> None:
160174class FakeStdin :
161175 """Provide a fake stdin type for things like raw_input() etc."""
162176
163- def __init__ (self , interface : ' CLIRepl' ) -> None :
177+ def __init__ (self , interface : " CLIRepl" ) -> None :
164178 """Take the curses Repl on init and assume it provides a get_key method
165179 which, fortunately, it does."""
166180
@@ -263,7 +277,7 @@ def readlines(self, size: int = -1) -> List[str]:
263277# Have to ignore the return type on this one because the colors variable
264278# is Optional[MutableMapping[str, int]] but for the purposes of this
265279# function it can't be None
266- def get_color (config : Config , name : str ) -> int : # type: ignore[return]
280+ def get_color (config : Config , name : str ) -> int : # type: ignore[return]
267281 global colors
268282 if colors :
269283 return colors [config .color_scheme [name ].lower ()]
@@ -315,7 +329,7 @@ def make_colors(config: Config) -> MutableMapping[str, int]:
315329
316330
317331class CLIInteraction (repl .Interaction ):
318- def __init__ (self , config : Config , statusbar : Optional [' Statusbar' ] = None ):
332+ def __init__ (self , config : Config , statusbar : Optional [" Statusbar" ] = None ):
319333 super ().__init__ (config , statusbar )
320334
321335 def confirm (self , q : str ) -> bool :
@@ -328,7 +342,9 @@ def confirm(self, q: str) -> bool:
328342
329343 return reply .lower () in (_ ("y" ), _ ("yes" ))
330344
331- def notify (self , s : str , n : int = 10 , wait_for_keypress : bool = False ) -> None :
345+ def notify (
346+ self , s : str , n : int = 10 , wait_for_keypress : bool = False
347+ ) -> None :
332348 if self .statusbar :
333349 self .statusbar .message (s , n )
334350
@@ -342,12 +358,12 @@ def file_prompt(self, s: str) -> Optional[str]:
342358
343359class CLIRepl (repl .Repl ):
344360 def __init__ (
345- self ,
346- scr : curses .window ,
347- interp : repl .Interpreter ,
348- statusbar : ' Statusbar' ,
349- config : Config ,
350- idle : Optional [Callable ] = None
361+ self ,
362+ scr : curses .window ,
363+ interp : repl .Interpreter ,
364+ statusbar : " Statusbar" ,
365+ config : Config ,
366+ idle : Optional [Callable ] = None ,
351367 ):
352368 super ().__init__ (interp , config )
353369 self .interp .writetb = self .writetb
@@ -412,10 +428,10 @@ def bs(self, delete_tabs: bool = True) -> int: # type: ignore[return-value]
412428 y , x = self .scr .getyx ()
413429
414430 if not self .s :
415- return None # type: ignore[return-value]
431+ return None # type: ignore[return-value]
416432
417433 if x == self .ix and y == self .iy :
418- return None # type: ignore[return-value]
434+ return None # type: ignore[return-value]
419435
420436 n = 1
421437
@@ -727,10 +743,10 @@ def lf(self) -> None:
727743 self .echo ("\n " )
728744
729745 def mkargspec (
730- self ,
731- topline : Any , # Named tuples don't seem to play nice with mypy
732- in_arg : Union [str , int ],
733- down : bool
746+ self ,
747+ topline : Any , # Named tuples don't seem to play nice with mypy
748+ in_arg : Union [str , int ],
749+ down : bool ,
734750 ) -> int :
735751 """This figures out what to do with the argspec and puts it nicely into
736752 the list window. It returns the number of lines used to display the
@@ -1062,7 +1078,9 @@ def p_key(self, key: str) -> Union[None, str, bool]:
10621078
10631079 return True
10641080
1065- def print_line (self , s : Optional [str ], clr : bool = False , newline : bool = False ) -> None :
1081+ def print_line (
1082+ self , s : Optional [str ], clr : bool = False , newline : bool = False
1083+ ) -> None :
10661084 """Chuck a line of text through the highlighter, move the cursor
10671085 to the beginning of the line and output it to the screen."""
10681086
@@ -1098,10 +1116,7 @@ def print_line(self, s: Optional[str], clr: bool = False, newline: bool = False)
10981116 self .mvc (1 )
10991117 self .cpos = t
11001118
1101- def prompt (
1102- self ,
1103- more : Any # I'm not sure of the type on this one
1104- ) -> None :
1119+ def prompt (self , more : Any ) -> None : # I'm not sure of the type on this one
11051120 """Show the appropriate Python prompt"""
11061121 if not more :
11071122 self .echo (
@@ -1193,7 +1208,9 @@ def repl(self) -> Tuple[Any, ...]:
11931208 self .s = ""
11941209 return self .exit_value
11951210
1196- def reprint_line (self , lineno : int , tokens : MutableMapping [_TokenType , str ]) -> None :
1211+ def reprint_line (
1212+ self , lineno : int , tokens : MutableMapping [_TokenType , str ]
1213+ ) -> None :
11971214 """Helper function for paren highlighting: Reprint line at offset
11981215 `lineno` in current input buffer."""
11991216 if not self .buffer or lineno == len (self .buffer ):
@@ -1291,12 +1308,12 @@ def write(self, s: str) -> None:
12911308 self .screen_hist .append (s .rstrip ())
12921309
12931310 def show_list (
1294- self ,
1295- items : List [str ],
1296- arg_pos : Union [str , int ],
1297- topline : Any = None , # Named tuples don't play nice with mypy
1298- formatter : Optional [Callable ] = None ,
1299- current_item : Optional [bool ] = None
1311+ self ,
1312+ items : List [str ],
1313+ arg_pos : Union [str , int ],
1314+ topline : Any = None , # Named tuples don't play nice with mypy
1315+ formatter : Optional [Callable ] = None ,
1316+ current_item : Optional [bool ] = None ,
13001317 ) -> None :
13011318 shared = ShowListState ()
13021319 y , x = self .scr .getyx ()
@@ -1591,16 +1608,18 @@ class Statusbar:
15911608
15921609 def __init__ (
15931610 self ,
1594- scr : curses .window ,
1595- pwin : curses .window ,
1596- background : int ,
1597- config : Config ,
1598- s : Optional [str ] = None ,
1599- c : Optional [int ] = None
1611+ scr : curses .window ,
1612+ pwin : curses .window ,
1613+ background : int ,
1614+ config : Config ,
1615+ s : Optional [str ] = None ,
1616+ c : Optional [int ] = None ,
16001617 ):
16011618 """Initialise the statusbar and display the initial text (if any)"""
16021619 self .size ()
1603- self .win : curses .window = newwin (background , self .h , self .w , self .y , self .x )
1620+ self .win : curses .window = newwin (
1621+ background , self .h , self .w , self .y , self .x
1622+ )
16041623
16051624 self .config = config
16061625
@@ -1724,7 +1743,9 @@ def clear(self) -> None:
17241743 self .win .clear ()
17251744
17261745
1727- def init_wins (scr : curses .window , config : Config ) -> Tuple [curses .window , Statusbar ]:
1746+ def init_wins (
1747+ scr : curses .window , config : Config
1748+ ) -> Tuple [curses .window , Statusbar ]:
17281749 """Initialise the two windows (the main repl interface and the little
17291750 status bar at the bottom with some stuff in it)"""
17301751 # TODO: Document better what stuff is on the status bar.
@@ -1788,10 +1809,16 @@ def gethw() -> Tuple[int, int]:
17881809
17891810 if platform .system () != "Windows" :
17901811 h , w = struct .unpack (
1791- "hhhh" , fcntl .ioctl (sys .__stdout__ , termios .TIOCGWINSZ , "\000 " * 8 ) # type:ignore[call-overload]
1812+ "hhhh" ,
1813+ fcntl .ioctl (
1814+ sys .__stdout__ , termios .TIOCGWINSZ , "\000 " * 8
1815+ ), # type:ignore[call-overload]
17921816 )[0 :2 ]
17931817 else :
1794- from ctypes import windll , create_string_buffer # type:ignore[attr-defined]
1818+ from ctypes import (
1819+ windll ,
1820+ create_string_buffer ,
1821+ ) # type:ignore[attr-defined]
17951822
17961823 # stdin handle is -10
17971824 # stdout handle is -11
@@ -1916,12 +1943,12 @@ def curses_wrapper(func: Callable, *args: Any, **kwargs: Any) -> Any:
19161943
19171944
19181945def 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
1946+ scr : curses .window ,
1947+ args : List [str ],
1948+ config : Config ,
1949+ interactive : bool = True ,
1950+ locals_ : Optional [MutableMapping [str , str ]] = None ,
1951+ banner : Optional [str ] = None ,
19251952) -> Tuple [Tuple [Any , ...], str ]:
19261953 """main function for the curses convenience wrapper
19271954
@@ -2031,9 +2058,9 @@ def main_curses(
20312058
20322059
20332060def main (
2034- args : Optional [List [str ]] = None ,
2035- locals_ : Optional [MutableMapping [str , str ]] = None ,
2036- banner : Optional [str ] = None
2061+ args : Optional [List [str ]] = None ,
2062+ locals_ : Optional [MutableMapping [str , str ]] = None ,
2063+ banner : Optional [str ] = None ,
20372064) -> Any :
20382065 translations .init ()
20392066
0 commit comments