1515from code_annotations .helpers import VerboseEcho
1616
1717
18- class AnnotationConfig ( object ) :
18+ class AnnotationConfig :
1919 """
2020 Configuration shared among all Code Annotations commands.
2121 """
@@ -51,10 +51,10 @@ def __init__(self, config_file_path, report_path_override=None, verbosity=1, sou
5151 self .echo .set_verbosity (verbosity )
5252
5353 self .report_path = report_path_override if report_path_override else raw_config ['report_path' ]
54- self .echo ("Configured for report path: {}" . format ( self .report_path ) )
54+ self .echo (f "Configured for report path: { self .report_path } " )
5555
5656 self .source_path = source_path_override if source_path_override else raw_config ['source_path' ]
57- self .echo ("Configured for source path: {}" . format ( self .source_path ) )
57+ self .echo (f "Configured for source path: { self .source_path } " )
5858
5959 self ._configure_coverage (raw_config .get ('coverage_target' , None ))
6060 self .report_template_dir = raw_config .get ('report_template_dir' )
@@ -125,7 +125,7 @@ def _is_annotation_token(self, token_or_group):
125125
126126 def _add_annotation_token (self , token ):
127127 if token in self .annotation_tokens :
128- raise ConfigurationException ('{ } is configured more than once, tokens must be unique.'. format ( token ) )
128+ raise ConfigurationException (f' { token } is configured more than once, tokens must be unique.' )
129129 self .annotation_tokens .append (token )
130130
131131 def _configure_coverage (self , coverage_target ):
@@ -141,14 +141,14 @@ def _configure_coverage(self, coverage_target):
141141 if coverage_target :
142142 try :
143143 self .coverage_target = float (coverage_target )
144- except (TypeError , ValueError ):
144+ except (TypeError , ValueError ) as error :
145145 raise ConfigurationException (
146- 'Coverage target must be a number between 0 and 100 not "{}".' . format ( coverage_target )
147- )
146+ f 'Coverage target must be a number between 0 and 100 not "{ coverage_target } ".'
147+ ) from error
148148
149149 if self .coverage_target < 0.0 or self .coverage_target > 100.0 :
150150 raise ConfigurationException (
151- 'Invalid coverage target. {} is not between 0 and 100.' . format ( self . coverage_target )
151+ f 'Invalid coverage target. { self . coverage_target } is not between 0 and 100.'
152152 )
153153 else :
154154 self .coverage_target = None
@@ -167,7 +167,7 @@ def _configure_group(self, group_name, group):
167167 self .groups [group_name ] = []
168168
169169 if not group or len (group ) == 1 :
170- raise ConfigurationException ('Group "{}" must have more than one annotation.' . format ( group_name ) )
170+ raise ConfigurationException (f 'Group "{ group_name } " must have more than one annotation.' )
171171
172172 for annotation in group :
173173 for annotation_token in annotation :
@@ -179,7 +179,7 @@ def _configure_group(self, group_name, group):
179179
180180 # Otherwise it should be a text type, if not then error out
181181 elif not self ._is_annotation_token (annotation_value ):
182- raise ConfigurationException ('{ } is an unknown annotation type.'. format ( annotation ) )
182+ raise ConfigurationException (f' { annotation } is an unknown annotation type.' )
183183
184184 self .groups [group_name ].append (annotation_token )
185185 self ._add_annotation_token (annotation_token )
@@ -219,15 +219,15 @@ def _configure_annotations(self, raw_config):
219219
220220 elif not self ._is_annotation_token (annotation ): # pragma: no cover
221221 raise TypeError (
222- '{ } is an unknown type, must be strings or lists.'. format ( annotation_token_or_group_name )
222+ f' { annotation_token_or_group_name } is an unknown type, must be strings or lists.'
223223 )
224224 else :
225225 self ._add_annotation_token (annotation_token_or_group_name )
226226 self .annotation_regexes .append (re .escape (annotation_token_or_group_name ))
227227
228- self .echo .echo_v ("Groups configured: {}" . format ( self .groups ) )
229- self .echo .echo_v ("Choices configured: {}" . format ( self .choices ) )
230- self .echo .echo_v ("Annotation tokens configured: {}" . format ( self .annotation_tokens ) )
228+ self .echo .echo_v (f "Groups configured: { self .groups } " )
229+ self .echo .echo_v (f "Choices configured: { self .choices } " )
230+ self .echo .echo_v (f "Annotation tokens configured: { self .annotation_tokens } " )
231231
232232 def _plugin_load_failed_handler (self , * args , ** kwargs ):
233233 """
@@ -281,7 +281,7 @@ def _configure_extensions(self):
281281 ))
282282
283283
284- class BaseSearch (object , metaclass = ABCMeta ):
284+ class BaseSearch (metaclass = ABCMeta ):
285285 """
286286 Base class for searchers.
287287 """
@@ -365,7 +365,7 @@ def _check_results_choices(self, annotation):
365365 )
366366 )
367367 elif choice in found_valid_choices :
368- self ._add_annotation_error (annotation , '"{}" is already present in this annotation.' . format ( choice ) )
368+ self ._add_annotation_error (annotation , f '"{ choice } " is already present in this annotation.' )
369369 else :
370370 found_valid_choices .append (choice )
371371 else :
@@ -446,7 +446,7 @@ def check_results(self, all_results):
446446 elif token in found_group_members :
447447 self ._add_annotation_error (
448448 annotation ,
449- '"{}" is already in the group that starts with "{}"' . format ( token , current_group )
449+ f '"{ token } " is already in the group that starts with "{ current_group } "'
450450 )
451451 current_group = None
452452 found_group_members = []
@@ -465,7 +465,7 @@ def check_results(self, all_results):
465465 # If we get here there is a problem with check_results' group_children not matching up with
466466 # our config's groups. That puts us in an unknown state, so we should quit.
467467 raise Exception (
468- 'group_children is out of sync with config.groups. {} is not in a group!' . format ( token )
468+ f 'group_children is out of sync with config.groups. { token } is not in a group!'
469469 )
470470
471471 found_group_members = [token ]
@@ -480,7 +480,7 @@ def check_results(self, all_results):
480480 found_group_members = []
481481
482482 if current_group :
483- self .errors .append ('File("{}") finished with an incomplete group {}!' . format ( filename , current_group ) )
483+ self .errors .append (f 'File("{ filename } ") finished with an incomplete group { current_group } !' )
484484
485485 return not self .errors
486486
@@ -531,15 +531,15 @@ def _format_results_for_report(self, all_results):
531531 current_group_id = 0
532532
533533 for filename in all_results :
534- self .echo .echo_vv ("report_format: formatting {}" . format ( filename ) )
534+ self .echo .echo_vv (f "report_format: formatting { filename } " )
535535 formatted_results [filename ] = []
536536 current_group = None
537537
538538 found_group_members = []
539539
540540 for annotation in all_results [filename ]:
541541 token = annotation ['annotation_token' ]
542- self .echo .echo_vvv ("report_format: formatting annotation token {}" . format ( token ) )
542+ self .echo .echo_vvv (f "report_format: formatting annotation token { token } " )
543543
544544 if current_group :
545545 if token not in self .config .groups [current_group ]:
@@ -572,7 +572,7 @@ def _format_results_for_report(self, all_results):
572572 current_group_id , current_group , token , annotation ['line_number' ])
573573 )
574574 else :
575- self .echo .echo_vv ('Adding single token {}.' . format ( token ) )
575+ self .echo .echo_vv (f 'Adding single token { token } .' )
576576 formatted_results [filename ].append (annotation )
577577
578578 # If we have all members, this group is done
@@ -603,7 +603,7 @@ def report(self, all_results, report_prefix=''):
603603
604604 formatted_results = self ._format_results_for_report (all_results )
605605
606- self .echo ("Generating report to {}" . format ( report_filename ) )
606+ self .echo (f "Generating report to { report_filename } " )
607607
608608 try :
609609 os .makedirs (self .config .report_path )
0 commit comments