@@ -144,7 +144,8 @@ def is_empty_or_comment(line):
144
144
return '' .join (reversed (list (filtered_src )))
145
145
146
146
def __str__ (self ):
147
- out = 'in %s %s `%s`' % (self ._publicity , self ._human , self .name )
147
+ out = 'in {0} {1} `{2}`' .format (self ._publicity , self ._human ,
148
+ self .name )
148
149
if self .skipped_error_codes :
149
150
out += ' (skipping {0})' .format (self .skipped_error_codes )
150
151
return out
@@ -395,17 +396,17 @@ def parse_all(self):
395
396
if self .current .value not in '([' :
396
397
raise AllError ('Could not evaluate contents of __all__. ' )
397
398
if self .current .value == '[' :
398
- msg = ( "%s WARNING: __all__ is defined as a list, this means "
399
- "pydocstyle cannot reliably detect contents of the __all__ "
400
- "variable, because it can be mutated. Change __all__ to be "
401
- "an (immutable) tuple, to remove this warning. Note, "
402
- "pydocstyle uses __all__ to detect which definitions are "
403
- "public, to warn if public definitions are missing "
404
- "docstrings. If __all__ is a (mutable) list, pydocstyle "
405
- "cannot reliably assume its contents. pydocstyle will "
406
- "proceed assuming __all__ is not mutated. \n "
407
- % self . filename )
408
- sys . stderr . write ( msg )
399
+ sys . stderr . write (
400
+ "{0} WARNING: __all__ is defined as a list, this means "
401
+ "pydocstyle cannot reliably detect contents of the __all__ "
402
+ "variable, because it can be mutated. Change __all__ to be "
403
+ "an (immutable) tuple, to remove this warning. Note, "
404
+ "pydocstyle uses __all__ to detect which definitions are "
405
+ "public, to warn if public definitions are missing "
406
+ "docstrings. If __all__ is a (mutable) list, pydocstyle "
407
+ "cannot reliably assume its contents. pydocstyle will "
408
+ "proceed assuming __all__ is not mutated. \n "
409
+ . format ( self . filename ) )
409
410
self .consume (tk .OP )
410
411
411
412
self .all = []
@@ -417,17 +418,17 @@ def parse_all(self):
417
418
self .current .value == ',' ):
418
419
all_content += self .current .value
419
420
else :
420
- raise AllError ('Unexpected token kind in __all__: %r . ' %
421
- self .current .kind )
421
+ raise AllError ('Unexpected token kind in __all__: {0!r} . '
422
+ . format ( self .current .kind ) )
422
423
self .stream .move ()
423
424
self .consume (tk .OP )
424
425
all_content += ")"
425
426
try :
426
427
self .all = eval (all_content , {})
427
428
except BaseException as e :
428
429
raise AllError ('Could not evaluate contents of __all__.'
429
- '\b The value was %s . The exception was:\n %s '
430
- % (all_content , e ))
430
+ '\b The value was {0} . The exception was:\n {1} '
431
+ . format (all_content , e ))
431
432
432
433
def parse_module (self ):
433
434
"""Parse a module (and its children) and return a Module object."""
@@ -605,9 +606,9 @@ def set_context(self, definition, explanation):
605
606
606
607
@property
607
608
def message (self ):
608
- ret = '%s: %s' % (self .code , self .short_desc )
609
+ ret = '{0}: {1}' . format (self .code , self .short_desc )
609
610
if self .context is not None :
610
- ret += ' (' + self .context % self .parameters + ')'
611
+ ret += ' (' + self .context . format ( * self .parameters ) + ')'
611
612
return ret
612
613
613
614
@property
@@ -623,7 +624,8 @@ def lines(self):
623
624
numbers_width = len (str (numbers_width ))
624
625
numbers_width = 6
625
626
for n , line in enumerate (lines_stripped ):
626
- source += '%*d: %s' % (numbers_width , n + offset , line )
627
+ source += '{{0}}{0}: {{1}}' .format (numbers_width ).format (
628
+ n + offset , line )
627
629
if n > 5 :
628
630
source += ' ...\n '
629
631
break
@@ -632,16 +634,16 @@ def lines(self):
632
634
def __str__ (self ):
633
635
self .explanation = '\n ' .join (l for l in self .explanation .split ('\n ' )
634
636
if not is_blank (l ))
635
- template = '%( filename)s:%( line)s %( definition)s :\n %( message)s '
637
+ template = '{ filename}:{ line} { definition} :\n { message} '
636
638
if self .source and self .explain :
637
- template += '\n \n %( explanation)s \n \n %( lines)s \n '
639
+ template += '\n \n { explanation} \n \n { lines} \n '
638
640
elif self .source and not self .explain :
639
- template += '\n \n %( lines)s \n '
641
+ template += '\n \n { lines} \n '
640
642
elif self .explain and not self .source :
641
- template += '\n \n %( explanation)s \n \n '
642
- return template % dict ((name , getattr (self , name )) for name in
643
+ template += '\n \n { explanation} \n \n '
644
+ return template . format ( ** dict ((name , getattr (self , name )) for name in
643
645
['filename' , 'line' , 'definition' , 'message' ,
644
- 'explanation' , 'lines' ])
646
+ 'explanation' , 'lines' ]))
645
647
646
648
__repr__ = __str__
647
649
@@ -690,7 +692,7 @@ def to_rst(cls):
690
692
for group in cls .groups :
691
693
table += sep_line
692
694
table += blank_line
693
- table += '|' + ( '**%s **' % group .name ).center (78 ) + '|\n '
695
+ table += '|' + '**{0} **' . format ( group .name ).center (78 ) + '|\n '
694
696
table += blank_line
695
697
for error in group .errors :
696
698
table += sep_line
@@ -710,17 +712,17 @@ def to_rst(cls):
710
712
711
713
D2xx = ErrorRegistry .create_group ('D2' , 'Whitespace Issues' )
712
714
D200 = D2xx .create_error ('D200' , 'One-line docstring should fit on one line '
713
- 'with quotes' , 'found %s ' )
715
+ 'with quotes' , 'found {0} ' )
714
716
D201 = D2xx .create_error ('D201' , 'No blank lines allowed before function '
715
- 'docstring' , 'found %s ' )
717
+ 'docstring' , 'found {0} ' )
716
718
D202 = D2xx .create_error ('D202' , 'No blank lines allowed after function '
717
- 'docstring' , 'found %s ' )
719
+ 'docstring' , 'found {0} ' )
718
720
D203 = D2xx .create_error ('D203' , '1 blank line required before class '
719
- 'docstring' , 'found %s ' )
721
+ 'docstring' , 'found {0} ' )
720
722
D204 = D2xx .create_error ('D204' , '1 blank line required after class '
721
- 'docstring' , 'found %s ' )
723
+ 'docstring' , 'found {0} ' )
722
724
D205 = D2xx .create_error ('D205' , '1 blank line required between summary line '
723
- 'and description' , 'found %s ' )
725
+ 'and description' , 'found {0} ' )
724
726
D206 = D2xx .create_error ('D206' , 'Docstring should be indented with spaces, '
725
727
'not tabs' )
726
728
D207 = D2xx .create_error ('D207' , 'Docstring is under-indented' )
@@ -730,27 +732,27 @@ def to_rst(cls):
730
732
D210 = D2xx .create_error ('D210' , 'No whitespaces allowed surrounding '
731
733
'docstring text' )
732
734
D211 = D2xx .create_error ('D211' , 'No blank lines allowed before class '
733
- 'docstring' , 'found %s ' )
735
+ 'docstring' , 'found {0} ' )
734
736
D212 = D2xx .create_error ('D212' , 'Multi-line docstring summary should start '
735
737
'at the first line' )
736
738
D213 = D2xx .create_error ('D213' , 'Multi-line docstring summary should start '
737
739
'at the second line' )
738
740
739
741
D3xx = ErrorRegistry .create_group ('D3' , 'Quotes Issues' )
740
742
D300 = D3xx .create_error ('D300' , 'Use """triple double quotes"""' ,
741
- 'found %s -quotes' )
743
+ 'found {0} -quotes' )
742
744
D301 = D3xx .create_error ('D301' , 'Use r""" if any backslashes in a docstring' )
743
745
D302 = D3xx .create_error ('D302' , 'Use u""" for Unicode docstrings' )
744
746
745
747
D4xx = ErrorRegistry .create_group ('D4' , 'Docstring Content Issues' )
746
748
D400 = D4xx .create_error ('D400' , 'First line should end with a period' ,
747
- 'not %r ' )
749
+ 'not {0!r} ' )
748
750
D401 = D4xx .create_error ('D401' , 'First line should be in imperative mood' ,
749
- '%r , not %r ' )
751
+ '{0!r} , not {1!r} ' )
750
752
D402 = D4xx .create_error ('D402' , 'First line should not be the function\' s '
751
753
'"signature"' )
752
754
D403 = D4xx .create_error ('D403' , 'First word of the first line should be '
753
- 'properly capitalized' , '%r , not %r ' )
755
+ 'properly capitalized' , '{0!r} , not {1!r} ' )
754
756
D404 = D4xx .create_error ('D404' , 'First word of the docstring should not '
755
757
'be `This`' )
756
758
@@ -1387,7 +1389,7 @@ def run_pydocstyle(use_pep257=False):
1387
1389
code = ReturnCode .no_violations_found
1388
1390
count = 0
1389
1391
for error in errors :
1390
- sys .stderr .write ('%s \n ' % error )
1392
+ sys .stderr .write ('{0} \n ' . format ( error ) )
1391
1393
code = ReturnCode .violations_found
1392
1394
count += 1
1393
1395
if run_conf .count :
0 commit comments