12125. Repeat steps 2-4 for other mypy runs (e.g. --py2)
1313"""
1414
15+ import argparse
1516import os
1617import re
1718import sys
18- import argparse
1919
20- parser = argparse .ArgumentParser (description = "Test runner for typeshed. "
21- "Patterns are unanchored regexps on the full path. " )
22- parser .add_argument ('-v' , '--verbose' , action = 'count' , default = 0 , help = "More output " )
23- parser .add_argument ('-n' , '--dry-run' , action = 'store_true' , help = "Don't actually run mypy " )
24- parser .add_argument ('-x' , '--exclude' , type = str , nargs = '*' , help = "Exclude pattern " )
25- parser .add_argument ('-p' , '--python-version' , type = str , nargs = '*' ,
26- help = "These versions only (major[.minor])" )
27- parser . add_argument ( '--platform' ,
28- help = "Run mypy for a certain OS platform (defaults to sys.platform)" )
29- parser . add_argument ( ' --warn-unused-ignores' , action = 'store_true' ,
30- help = "Run mypy with --warn-unused-ignores "
31- "(hint: only get rid of warnings that are "
32- "unused for all platforms and Python versions)" )
20+ parser = argparse .ArgumentParser (description = "Test runner for typeshed. " "Patterns are unanchored regexps on the full path." )
21+ parser . add_argument ( "-v" , "--verbose" , action = "count" , default = 0 , help = "More output " )
22+ parser .add_argument ("-n" , "--dry-run" , action = "store_true" , help = "Don't actually run mypy " )
23+ parser .add_argument ("-x" , "--exclude" , type = str , nargs = "*" , help = "Exclude pattern " )
24+ parser .add_argument ("-p" , "--python-version" , type = str , nargs = "*" , help = "These versions only (major[.minor]) " )
25+ parser .add_argument ("--platform" , help = "Run mypy for a certain OS platform (defaults to sys.platform)" )
26+ parser . add_argument (
27+ "--warn-unused-ignores" ,
28+ action = "store_true" ,
29+ help = "Run mypy with --warn-unused-ignores "
30+ "(hint: only get rid of warnings that are "
31+ "unused for all platforms and Python versions)" ,
32+ )
3333
34- parser .add_argument (' filter' , type = str , nargs = '*' , help = "Include pattern (default all)" )
34+ parser .add_argument (" filter" , type = str , nargs = "*" , help = "Include pattern (default all)" )
3535
3636
3737def log (args , * varargs ):
@@ -41,36 +41,35 @@ def log(args, *varargs):
4141
4242def match (fn , args , exclude_list ):
4343 if exclude_list .match (fn ):
44- log (args , fn , ' exluded by exclude list' )
44+ log (args , fn , " exluded by exclude list" )
4545 return False
4646 if not args .filter and not args .exclude :
47- log (args , fn , ' accept by default' )
47+ log (args , fn , " accept by default" )
4848 return True
4949 if args .exclude :
5050 for f in args .exclude :
5151 if re .search (f , fn ):
52- log (args , fn , ' excluded by pattern' , f )
52+ log (args , fn , " excluded by pattern" , f )
5353 return False
5454 if args .filter :
5555 for f in args .filter :
5656 if re .search (f , fn ):
57- log (args , fn , ' accepted by pattern' , f )
57+ log (args , fn , " accepted by pattern" , f )
5858 return True
5959 if args .filter :
60- log (args , fn , ' rejected (no pattern matches)' )
60+ log (args , fn , " rejected (no pattern matches)" )
6161 return False
62- log (args , fn , ' accepted (no exclude pattern matches)' )
62+ log (args , fn , " accepted (no exclude pattern matches)" )
6363 return True
6464
6565
6666def libpath (major , minor ):
67- versions = ['%d.%d' % (major , minor )
68- for minor in reversed (range (minor + 1 ))]
67+ versions = ["%d.%d" % (major , minor ) for minor in reversed (range (minor + 1 ))]
6968 versions .append (str (major ))
70- versions .append (' 2and3' )
69+ versions .append (" 2and3" )
7170 paths = []
7271 for v in versions :
73- for top in [' stdlib' , ' third_party' ]:
72+ for top in [" stdlib" , " third_party" ]:
7473 p = os .path .join (top , v )
7574 if os .path .isdir (p ):
7675 paths .append (p )
@@ -81,8 +80,7 @@ def main():
8180 args = parser .parse_args ()
8281
8382 with open (os .path .join (os .path .dirname (__file__ ), "mypy_exclude_list.txt" )) as f :
84- exclude_list = re .compile ("(%s)$" % "|" .join (
85- re .findall (r"^\s*([^\s#]+)\s*(?:#.*)?$" , f .read (), flags = re .M )))
83+ exclude_list = re .compile ("(%s)$" % "|" .join (re .findall (r"^\s*([^\s#]+)\s*(?:#.*)?$" , f .read (), flags = re .M )))
8684
8785 try :
8886 from mypy .main import main as mypy_main
@@ -92,8 +90,7 @@ def main():
9290
9391 versions = [(3 , 9 ), (3 , 8 ), (3 , 7 ), (3 , 6 ), (3 , 5 ), (2 , 7 )]
9492 if args .python_version :
95- versions = [v for v in versions
96- if any (('%d.%d' % v ).startswith (av ) for av in args .python_version )]
93+ versions = [v for v in versions if any (("%d.%d" % v ).startswith (av ) for av in args .python_version )]
9794 if not versions :
9895 print ("--- no versions selected ---" )
9996 sys .exit (1 )
@@ -103,51 +100,50 @@ def main():
103100 for major , minor in versions :
104101 roots = libpath (major , minor )
105102 files = []
106- seen = {' __builtin__' , ' builtins' , ' typing' } # Always ignore these.
103+ seen = {" __builtin__" , " builtins" , " typing" } # Always ignore these.
107104 for root in roots :
108105 names = os .listdir (root )
109106 for name in names :
110107 full = os .path .join (root , name )
111108 mod , ext = os .path .splitext (name )
112- if mod in seen or mod .startswith ('.' ):
109+ if mod in seen or mod .startswith ("." ):
113110 continue
114- if ext in [' .pyi' , ' .py' ]:
111+ if ext in [" .pyi" , " .py" ]:
115112 if match (full , args , exclude_list ):
116113 seen .add (mod )
117114 files .append (full )
118- elif (os .path .isfile (os .path .join (full , '__init__.pyi' )) or
119- os .path .isfile (os .path .join (full , '__init__.py' ))):
115+ elif os .path .isfile (os .path .join (full , "__init__.pyi" )) or os .path .isfile (os .path .join (full , "__init__.py" )):
120116 for r , ds , fs in os .walk (full ):
121117 ds .sort ()
122118 fs .sort ()
123119 for f in fs :
124120 m , x = os .path .splitext (f )
125- if x in [' .pyi' , ' .py' ]:
121+ if x in [" .pyi" , " .py" ]:
126122 fn = os .path .join (r , f )
127123 if match (fn , args , exclude_list ):
128124 seen .add (mod )
129125 files .append (fn )
130126 if files :
131127 runs += 1
132- flags = [' --python-version' , ' %d.%d' % (major , minor )]
133- flags .append (' --strict-optional' )
134- flags .append (' --no-site-packages' )
135- flags .append (' --show-traceback' )
136- flags .append (' --no-implicit-optional' )
137- flags .append (' --disallow-any-generics' )
138- flags .append (' --disallow-subclassing-any' )
128+ flags = [" --python-version" , " %d.%d" % (major , minor )]
129+ flags .append (" --strict-optional" )
130+ flags .append (" --no-site-packages" )
131+ flags .append (" --show-traceback" )
132+ flags .append (" --no-implicit-optional" )
133+ flags .append (" --disallow-any-generics" )
134+ flags .append (" --disallow-subclassing-any" )
139135 if args .warn_unused_ignores :
140- flags .append (' --warn-unused-ignores' )
136+ flags .append (" --warn-unused-ignores" )
141137 if args .platform :
142- flags .extend ([' --platform' , args .platform ])
143- sys .argv = [' mypy' ] + flags + files
138+ flags .extend ([" --platform" , args .platform ])
139+ sys .argv = [" mypy" ] + flags + files
144140 if args .verbose :
145- print ("running" , ' ' .join (sys .argv ))
141+ print ("running" , " " .join (sys .argv ))
146142 else :
147- print ("running mypy" , ' ' .join (flags ), "# with" , len (files ), "files" )
143+ print ("running mypy" , " " .join (flags ), "# with" , len (files ), "files" )
148144 try :
149145 if not args .dry_run :
150- mypy_main ('' , sys .stdout , sys .stderr )
146+ mypy_main ("" , sys .stdout , sys .stderr )
151147 except SystemExit as err :
152148 code = max (code , err .code )
153149 if code :
@@ -158,5 +154,5 @@ def main():
158154 sys .exit (1 )
159155
160156
161- if __name__ == ' __main__' :
157+ if __name__ == " __main__" :
162158 main ()
0 commit comments