@@ -44,7 +44,7 @@ def __init__(self, program="flake8", version=flake8.__version__):
44
44
#: The timestamp when the Application instance was instantiated.
45
45
self .start_time = time .time ()
46
46
#: The timestamp when the Application finished reported errors.
47
- self .end_time : float = None
47
+ self .end_time : Optional [ float ] = None
48
48
#: The name of the program being run
49
49
self .program = program
50
50
#: The version of the program being run
@@ -63,24 +63,26 @@ def __init__(self, program="flake8", version=flake8.__version__):
63
63
options .register_default_options (self .option_manager )
64
64
65
65
#: The instance of :class:`flake8.plugins.manager.Checkers`
66
- self .check_plugins : plugin_manager .Checkers = None
66
+ self .check_plugins : Optional [ plugin_manager .Checkers ] = None
67
67
#: The instance of :class:`flake8.plugins.manager.ReportFormatters`
68
- self .formatting_plugins : plugin_manager .ReportFormatters = None
68
+ self .formatting_plugins : Optional [
69
+ plugin_manager .ReportFormatters
70
+ ] = None
69
71
#: The user-selected formatter from :attr:`formatting_plugins`
70
- self .formatter : BaseFormatter = None
72
+ self .formatter : Optional [ BaseFormatter ] = None
71
73
#: The :class:`flake8.style_guide.StyleGuideManager` built from the
72
74
#: user's options
73
- self .guide : style_guide .StyleGuideManager = None
75
+ self .guide : Optional [ style_guide .StyleGuideManager ] = None
74
76
#: The :class:`flake8.checker.Manager` that will handle running all of
75
77
#: the checks selected by the user.
76
- self .file_checker_manager : checker .Manager = None
78
+ self .file_checker_manager : Optional [ checker .Manager ] = None
77
79
78
80
#: The user-supplied options parsed into an instance of
79
81
#: :class:`argparse.Namespace`
80
- self .options : argparse .Namespace = None
82
+ self .options : Optional [ argparse .Namespace ] = None
81
83
#: The left over arguments that were not parsed by
82
84
#: :attr:`option_manager`
83
- self .args : List [str ] = None
85
+ self .args : Optional [ List [str ] ] = None
84
86
#: The number of errors, warnings, and other messages after running
85
87
#: flake8 and taking into account ignored errors and lines.
86
88
self .result_count = 0
@@ -128,6 +130,7 @@ def exit(self) -> None:
128
130
This should be the last thing called on the application instance. It
129
131
will check certain options and exit appropriately.
130
132
"""
133
+ assert self .options is not None
131
134
if self .options .count :
132
135
print (self .result_count )
133
136
@@ -162,8 +165,10 @@ def find_plugins(self, config_finder: config.ConfigFileFinder) -> None:
162
165
163
166
def register_plugin_options (self ) -> None :
164
167
"""Register options provided by plugins to our option manager."""
168
+ assert self .check_plugins is not None
165
169
self .check_plugins .register_options (self .option_manager )
166
170
self .check_plugins .register_plugin_versions (self .option_manager )
171
+ assert self .formatting_plugins is not None
167
172
self .formatting_plugins .register_options (self .option_manager )
168
173
169
174
def parse_configuration_and_cli (
@@ -190,15 +195,18 @@ def parse_configuration_and_cli(
190
195
if not self .parsed_diff :
191
196
self .exit ()
192
197
198
+ assert self .check_plugins is not None
193
199
self .check_plugins .provide_options (
194
200
self .option_manager , self .options , self .args
195
201
)
202
+ assert self .formatting_plugins is not None
196
203
self .formatting_plugins .provide_options (
197
204
self .option_manager , self .options , self .args
198
205
)
199
206
200
207
def formatter_for (self , formatter_plugin_name ):
201
208
"""Retrieve the formatter class by plugin name."""
209
+ assert self .formatting_plugins is not None
202
210
default_formatter = self .formatting_plugins ["default" ]
203
211
formatter_plugin = self .formatting_plugins .get (formatter_plugin_name )
204
212
if formatter_plugin is None :
@@ -214,6 +222,7 @@ def make_formatter(
214
222
self , formatter_class : Optional [Type ["BaseFormatter" ]] = None
215
223
) -> None :
216
224
"""Initialize a formatter based on the parsed options."""
225
+ assert self .options is not None
217
226
format_plugin = self .options .format
218
227
if 1 <= self .options .quiet < 2 :
219
228
format_plugin = "quiet-filename"
@@ -227,6 +236,8 @@ def make_formatter(
227
236
228
237
def make_guide (self ) -> None :
229
238
"""Initialize our StyleGuide."""
239
+ assert self .formatter is not None
240
+ assert self .options is not None
230
241
self .guide = style_guide .StyleGuideManager (
231
242
self .options , self .formatter
232
243
)
@@ -252,6 +263,7 @@ def run_checks(self, files: Optional[List[str]] = None) -> None:
252
263
:param list files:
253
264
List of filenames to process
254
265
"""
266
+ assert self .file_checker_manager is not None
255
267
if self .running_against_diff :
256
268
files = sorted (self .parsed_diff )
257
269
self .file_checker_manager .start (files )
@@ -267,9 +279,12 @@ def run_checks(self, files: Optional[List[str]] = None) -> None:
267
279
268
280
def report_benchmarks (self ):
269
281
"""Aggregate, calculate, and report benchmarks for this run."""
282
+ assert self .options is not None
270
283
if not self .options .benchmark :
271
284
return
272
285
286
+ assert self .file_checker_manager is not None
287
+ assert self .end_time is not None
273
288
time_elapsed = self .end_time - self .start_time
274
289
statistics = [("seconds elapsed" , time_elapsed )]
275
290
add_statistic = statistics .append
@@ -280,6 +295,7 @@ def report_benchmarks(self):
280
295
per_second_description = f"{ statistic } processed per second"
281
296
add_statistic ((per_second_description , int (value / time_elapsed )))
282
297
298
+ assert self .formatter is not None
283
299
self .formatter .show_benchmarks (statistics )
284
300
285
301
def report_errors (self ) -> None :
@@ -289,6 +305,7 @@ def report_errors(self) -> None:
289
305
number of errors, warnings, and other messages found.
290
306
"""
291
307
LOG .info ("Reporting errors" )
308
+ assert self .file_checker_manager is not None
292
309
results = self .file_checker_manager .report ()
293
310
self .total_result_count , self .result_count = results
294
311
LOG .info (
@@ -299,9 +316,12 @@ def report_errors(self) -> None:
299
316
300
317
def report_statistics (self ):
301
318
"""Aggregate and report statistics from this run."""
319
+ assert self .options is not None
302
320
if not self .options .statistics :
303
321
return
304
322
323
+ assert self .formatter is not None
324
+ assert self .guide is not None
305
325
self .formatter .show_statistics (self .guide .stats )
306
326
307
327
def initialize (self , argv : List [str ]) -> None :
@@ -332,6 +352,7 @@ def initialize(self, argv: List[str]) -> None:
332
352
333
353
def report (self ):
334
354
"""Report errors, statistics, and benchmarks."""
355
+ assert self .formatter is not None
335
356
self .formatter .start ()
336
357
self .report_errors ()
337
358
self .report_statistics ()
0 commit comments