77import re
88import sys
99from pathlib import Path
10- from typing import Callable , Iterator , List , Optional , Tuple
10+ from typing import Callable , Iterator , List , Optional , Tuple , Union
1111
1212from decorator import contextmanager
1313
1414
1515@contextmanager
16- def temp_environ ():
16+ def temp_environ () -> Iterator [ None ] :
1717 """Allow the ability to set os.environ temporarily"""
1818 environ = dict (os .environ )
1919 try :
@@ -24,7 +24,7 @@ def temp_environ():
2424
2525
2626@contextmanager
27- def temp_path ():
27+ def temp_path () -> Iterator [ None ] :
2828 """A context manager which allows the ability to set sys.path temporarily"""
2929 path = sys .path [:]
3030 try :
@@ -34,7 +34,7 @@ def temp_path():
3434
3535
3636@contextmanager
37- def temp_sys_modules ():
37+ def temp_sys_modules () -> Iterator [ None ] :
3838 sys_modules = sys .modules .copy ()
3939 try :
4040 yield
@@ -56,14 +56,14 @@ def fname_to_module(fpath: Path, root_path: Path) -> Optional[str]:
5656
5757
5858class TypecheckAssertionError (AssertionError ):
59- def __init__ (self , error_message : Optional [str ] = None , lineno : int = 0 ):
60- self .error_message = error_message
59+ def __init__ (self , error_message : Optional [str ] = None , lineno : int = 0 ) -> None :
60+ self .error_message = error_message or ''
6161 self .lineno = lineno
6262
63- def first_line (self ):
63+ def first_line (self ) -> str :
6464 return self .__class__ .__name__ + '(message="Invalid output")'
6565
66- def __str__ (self ):
66+ def __str__ (self ) -> str :
6767 return self .error_message
6868
6969
@@ -258,7 +258,8 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str]) -> None:
258258 lineno = lineno )
259259
260260
261- def build_output_line (fname : str , lnum : int , severity : str , message : str , col = None ) -> str :
261+ def build_output_line (fname : str , lnum : int , severity : str , message : str ,
262+ col : Optional [str ] = None ) -> str :
262263 if col is None :
263264 return f'{ fname } :{ lnum + 1 } : { severity } : { message } '
264265 else :
@@ -294,7 +295,7 @@ def extract_errors_from_comments(fname: str, input_lines: List[str]) -> List[str
294295
295296
296297def get_func_first_lnum (attr : Callable [..., None ]) -> Optional [Tuple [int , List [str ]]]:
297- lines , _ = inspect .getsourcelines (attr ) # type: ignore[arg-type]
298+ lines , _ = inspect .getsourcelines (attr )
298299 for lnum , line in enumerate (lines ):
299300 no_space_line = line .strip ()
300301 if f'def { attr .__name__ } ' in no_space_line :
@@ -303,7 +304,7 @@ def get_func_first_lnum(attr: Callable[..., None]) -> Optional[Tuple[int, List[s
303304
304305
305306@contextmanager
306- def cd (path ) :
307+ def cd (path : Union [ str , Path ]) -> Iterator [ None ] :
307308 """Context manager to temporarily change working directories"""
308309 if not path :
309310 return
0 commit comments