5
5
from pprint import pprint
6
6
7
7
SUBS = [
8
- ('from .._backends.auto import AutoBackend' , 'from .._backends.sync import SyncBackend' ),
8
+ (
9
+ "from .._backends.auto import AutoBackend" ,
10
+ "from .._backends.sync import SyncBackend" ,
11
+ ),
9
12
("import trio as concurrency" , "from tests import concurrency" ),
10
13
("AsyncIterator" , "Iterator" ),
11
14
("Async([A-Z][A-Za-z0-9_]*)" , r"\2" ),
32
35
USED_SUBS = set ()
33
36
34
37
35
- def unasync_line (line ) :
38
+ def unasync_line (line : str ) -> str :
36
39
for index , (regex , repl ) in enumerate (COMPILED_SUBS ):
37
40
old_line = line
38
41
line = re .sub (regex , repl , line )
@@ -41,15 +44,15 @@ def unasync_line(line):
41
44
return line
42
45
43
46
44
- def unasync_file (in_path , out_path ) :
47
+ def unasync_file (in_path : str , out_path : str ) -> None :
45
48
with open (in_path , "r" ) as in_file :
46
49
with open (out_path , "w" , newline = "" ) as out_file :
47
50
for line in in_file .readlines ():
48
51
line = unasync_line (line )
49
52
out_file .write (line )
50
53
51
54
52
- def unasync_file_check (in_path , out_path ) :
55
+ def unasync_file_check (in_path : str , out_path : str ) -> None :
53
56
with open (in_path , "r" ) as in_file :
54
57
with open (out_path , "r" ) as out_file :
55
58
for in_line , out_line in zip (in_file .readlines (), out_file .readlines ()):
@@ -62,7 +65,7 @@ def unasync_file_check(in_path, out_path):
62
65
sys .exit (1 )
63
66
64
67
65
- def unasync_dir (in_dir , out_dir , check_only = False ):
68
+ def unasync_dir (in_dir : str , out_dir : str , check_only : bool = False ) -> None :
66
69
for dirpath , dirnames , filenames in os .walk (in_dir ):
67
70
for filename in filenames :
68
71
if not filename .endswith (".py" ):
@@ -77,7 +80,7 @@ def unasync_dir(in_dir, out_dir, check_only=False):
77
80
unasync_file (in_path , out_path )
78
81
79
82
80
- def main ():
83
+ def main () -> None :
81
84
check_only = "--check" in sys .argv
82
85
unasync_dir ("httpcore/_async" , "httpcore/_sync" , check_only = check_only )
83
86
unasync_dir ("tests/_async" , "tests/_sync" , check_only = check_only )
0 commit comments