7
7
import re
8
8
import sys
9
9
from pathlib import Path
10
- from typing import Callable , Iterator , List , Optional , Tuple
10
+ from typing import Callable , Iterator , List , Optional , Tuple , Union
11
11
12
12
from decorator import contextmanager
13
13
14
14
15
15
@contextmanager
16
- def temp_environ ():
16
+ def temp_environ () -> Iterator [ None ] :
17
17
"""Allow the ability to set os.environ temporarily"""
18
18
environ = dict (os .environ )
19
19
try :
@@ -24,7 +24,7 @@ def temp_environ():
24
24
25
25
26
26
@contextmanager
27
- def temp_path ():
27
+ def temp_path () -> Iterator [ None ] :
28
28
"""A context manager which allows the ability to set sys.path temporarily"""
29
29
path = sys .path [:]
30
30
try :
@@ -34,7 +34,7 @@ def temp_path():
34
34
35
35
36
36
@contextmanager
37
- def temp_sys_modules ():
37
+ def temp_sys_modules () -> Iterator [ None ] :
38
38
sys_modules = sys .modules .copy ()
39
39
try :
40
40
yield
@@ -56,14 +56,14 @@ def fname_to_module(fpath: Path, root_path: Path) -> Optional[str]:
56
56
57
57
58
58
class 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 ''
61
61
self .lineno = lineno
62
62
63
- def first_line (self ):
63
+ def first_line (self ) -> str :
64
64
return self .__class__ .__name__ + '(message="Invalid output")'
65
65
66
- def __str__ (self ):
66
+ def __str__ (self ) -> str :
67
67
return self .error_message
68
68
69
69
@@ -258,7 +258,8 @@ def assert_string_arrays_equal(expected: List[str], actual: List[str]) -> None:
258
258
lineno = lineno )
259
259
260
260
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 :
262
263
if col is None :
263
264
return f'{ fname } :{ lnum + 1 } : { severity } : { message } '
264
265
else :
@@ -294,7 +295,7 @@ def extract_errors_from_comments(fname: str, input_lines: List[str]) -> List[str
294
295
295
296
296
297
def 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 )
298
299
for lnum , line in enumerate (lines ):
299
300
no_space_line = line .strip ()
300
301
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
303
304
304
305
305
306
@contextmanager
306
- def cd (path ) :
307
+ def cd (path : Union [ str , Path ]) -> Iterator [ None ] :
307
308
"""Context manager to temporarily change working directories"""
308
309
if not path :
309
310
return
0 commit comments