@@ -85,8 +85,8 @@ def __init__(self, style_guide, arguments, checker_plugins):
85
85
self .options = style_guide .options
86
86
self .checks = checker_plugins
87
87
self .jobs = self ._job_count ()
88
- self ._all_checkers = [] # type: List[FileChecker ]
89
- self .checkers = [] # type: List[FileChecker ]
88
+ self ._all_checkers : List [ FileChecker ] = [ ]
89
+ self .checkers : List [ FileChecker ] = [ ]
90
90
self .statistics = {
91
91
"files" : 0 ,
92
92
"logical lines" : 0 ,
@@ -103,8 +103,7 @@ def _process_statistics(self):
103
103
self .statistics [statistic ] += checker .statistics [statistic ]
104
104
self .statistics ["files" ] += len (self .checkers )
105
105
106
- def _job_count (self ):
107
- # type: () -> int
106
+ def _job_count (self ) -> int :
108
107
# First we walk through all of our error cases:
109
108
# - multiprocessing library is not present
110
109
# - we're running on windows in which case we know we have significant
@@ -165,8 +164,7 @@ def _handle_results(self, filename, results):
165
164
)
166
165
return reported_results_count
167
166
168
- def is_path_excluded (self , path ):
169
- # type: (str) -> bool
167
+ def is_path_excluded (self , path : str ) -> bool :
170
168
"""Check if a path is excluded.
171
169
172
170
:param str path:
@@ -189,8 +187,7 @@ def is_path_excluded(self, path):
189
187
logger = LOG ,
190
188
)
191
189
192
- def make_checkers (self , paths = None ):
193
- # type: (Optional[List[str]]) -> None
190
+ def make_checkers (self , paths : Optional [List [str ]] = None ) -> None :
194
191
"""Create checkers for each file."""
195
192
if paths is None :
196
193
paths = self .arguments
@@ -235,8 +232,7 @@ def should_create_file_checker(filename, argument):
235
232
self .checkers = [c for c in self ._all_checkers if c .should_process ]
236
233
LOG .info ("Checking %d files" , len (self .checkers ))
237
234
238
- def report (self ):
239
- # type: () -> Tuple[int, int]
235
+ def report (self ) -> Tuple [int , int ]:
240
236
"""Report all of the errors found in the managed file checkers.
241
237
242
238
This iterates over each of the checkers and reports the errors sorted
@@ -258,11 +254,11 @@ def report(self):
258
254
results_found += len (results )
259
255
return (results_found , results_reported )
260
256
261
- def run_parallel (self ): # type: () -> None
257
+ def run_parallel (self ) -> None :
262
258
"""Run the checkers in parallel."""
263
259
# fmt: off
264
- final_results = collections . defaultdict ( list ) # type : Dict[str, List[Tuple[str, int, int, str, Optional[str]]]] # noqa: E501
265
- final_statistics = collections . defaultdict ( dict ) # type : Dict[str, Dict[str, int]] # noqa: E501
260
+ final_results : Dict [str , List [Tuple [str , int , int , str , Optional [str ]]]] = collections . defaultdict ( list ) # noqa: E501
261
+ final_statistics : Dict [str , Dict [str , int ]] = collections . defaultdict ( dict ) # noqa: E501
266
262
# fmt: on
267
263
268
264
pool = _try_initialize_processpool (self .jobs )
@@ -297,12 +293,12 @@ def run_parallel(self): # type: () -> None
297
293
checker .results = final_results [filename ]
298
294
checker .statistics = final_statistics [filename ]
299
295
300
- def run_serial (self ): # type: () -> None
296
+ def run_serial (self ) -> None :
301
297
"""Run the checkers in serial."""
302
298
for checker in self .checkers :
303
299
checker .run_checks ()
304
300
305
- def run (self ): # type: () -> None
301
+ def run (self ) -> None :
306
302
"""Run all the checkers.
307
303
308
304
This will intelligently decide whether to run the checks in parallel
@@ -356,9 +352,7 @@ def __init__(self, filename, checks, options):
356
352
self .options = options
357
353
self .filename = filename
358
354
self .checks = checks
359
- # fmt: off
360
- self .results = [] # type: List[Tuple[str, int, int, str, Optional[str]]] # noqa: E501
361
- # fmt: on
355
+ self .results : List [Tuple [str , int , int , str , Optional [str ]]] = []
362
356
self .statistics = {
363
357
"tokens" : 0 ,
364
358
"logical lines" : 0 ,
@@ -372,12 +366,11 @@ def __init__(self, filename, checks, options):
372
366
self .should_process = not self .processor .should_ignore_file ()
373
367
self .statistics ["physical lines" ] = len (self .processor .lines )
374
368
375
- def __repr__ (self ): # type: () -> str
369
+ def __repr__ (self ) -> str :
376
370
"""Provide helpful debugging representation."""
377
371
return f"FileChecker for { self .filename } "
378
372
379
- def _make_processor (self ):
380
- # type: () -> Optional[processor.FileProcessor]
373
+ def _make_processor (self ) -> Optional [processor .FileProcessor ]:
381
374
try :
382
375
return processor .FileProcessor (self .filename , self .options )
383
376
except OSError as e :
@@ -391,8 +384,13 @@ def _make_processor(self):
391
384
self .report ("E902" , 0 , 0 , message )
392
385
return None
393
386
394
- def report (self , error_code , line_number , column , text ):
395
- # type: (Optional[str], int, int, str) -> str
387
+ def report (
388
+ self ,
389
+ error_code : Optional [str ],
390
+ line_number : int ,
391
+ column : int ,
392
+ text : str ,
393
+ ) -> str :
396
394
"""Report an error by storing it in the results list."""
397
395
if error_code is None :
398
396
error_code , text = text .split (" " , 1 )
@@ -468,7 +466,7 @@ def _extract_syntax_information(exception):
468
466
column -= column_offset
469
467
return row , column
470
468
471
- def run_ast_checks (self ): # type: () -> None
469
+ def run_ast_checks (self ) -> None :
472
470
"""Run all checks expecting an abstract syntax tree."""
473
471
try :
474
472
ast = self .processor .build_ast ()
@@ -610,8 +608,9 @@ def handle_newline(self, token_type):
610
608
else :
611
609
self .run_logical_checks ()
612
610
613
- def check_physical_eol (self , token , prev_physical ):
614
- # type: (processor._Token, str) -> None
611
+ def check_physical_eol (
612
+ self , token : processor ._Token , prev_physical : str
613
+ ) -> None :
615
614
"""Run physical checks if and only if it is at the end of the line."""
616
615
# a newline token ends a single physical line.
617
616
if processor .is_eol_token (token ):
@@ -640,13 +639,14 @@ def check_physical_eol(self, token, prev_physical):
640
639
self .run_physical_checks (line + "\n " )
641
640
642
641
643
- def _pool_init (): # type: () -> None
642
+ def _pool_init () -> None :
644
643
"""Ensure correct signaling of ^C using multiprocessing.Pool."""
645
644
signal .signal (signal .SIGINT , signal .SIG_IGN )
646
645
647
646
648
- def _try_initialize_processpool (job_count ):
649
- # type: (int) -> Optional[multiprocessing.pool.Pool]
647
+ def _try_initialize_processpool (
648
+ job_count : int ,
649
+ ) -> Optional [multiprocessing .pool .Pool ]:
650
650
"""Return a new process pool instance if we are able to create one."""
651
651
try :
652
652
return multiprocessing .Pool (job_count , _pool_init )
@@ -675,8 +675,9 @@ def _run_checks(checker):
675
675
return checker .run_checks ()
676
676
677
677
678
- def find_offset (offset , mapping ):
679
- # type: (int, processor._LogicalMapping) -> Tuple[int, int]
678
+ def find_offset (
679
+ offset : int , mapping : processor ._LogicalMapping
680
+ ) -> Tuple [int , int ]:
680
681
"""Find the offset tuple for a single offset."""
681
682
if isinstance (offset , tuple ):
682
683
return offset
0 commit comments