Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 4d43201

Browse files
committed
Remove % in str for .format
1 parent 98623fe commit 4d43201

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed

src/pydocstyle.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def is_empty_or_comment(line):
144144
return ''.join(reversed(list(filtered_src)))
145145

146146
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)
148149
if self.skipped_error_codes:
149150
out += ' (skipping {0})'.format(self.skipped_error_codes)
150151
return out
@@ -395,17 +396,17 @@ def parse_all(self):
395396
if self.current.value not in '([':
396397
raise AllError('Could not evaluate contents of __all__. ')
397398
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))
409410
self.consume(tk.OP)
410411

411412
self.all = []
@@ -417,17 +418,17 @@ def parse_all(self):
417418
self.current.value == ','):
418419
all_content += self.current.value
419420
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))
422423
self.stream.move()
423424
self.consume(tk.OP)
424425
all_content += ")"
425426
try:
426427
self.all = eval(all_content, {})
427428
except BaseException as e:
428429
raise AllError('Could not evaluate contents of __all__.'
429-
'\bThe value was %s. The exception was:\n%s'
430-
% (all_content, e))
430+
'\bThe value was {0}. The exception was:\n{1}'
431+
.format(all_content, e))
431432

432433
def parse_module(self):
433434
"""Parse a module (and its children) and return a Module object."""
@@ -605,9 +606,9 @@ def set_context(self, definition, explanation):
605606

606607
@property
607608
def message(self):
608-
ret = '%s: %s' % (self.code, self.short_desc)
609+
ret = '{0}: {1}'.format(self.code, self.short_desc)
609610
if self.context is not None:
610-
ret += ' (' + self.context % self.parameters + ')'
611+
ret += ' (' + self.context.format(*self.parameters) + ')'
611612
return ret
612613

613614
@property
@@ -623,7 +624,8 @@ def lines(self):
623624
numbers_width = len(str(numbers_width))
624625
numbers_width = 6
625626
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)
627629
if n > 5:
628630
source += ' ...\n'
629631
break
@@ -632,16 +634,16 @@ def lines(self):
632634
def __str__(self):
633635
self.explanation = '\n'.join(l for l in self.explanation.split('\n')
634636
if not is_blank(l))
635-
template = '%(filename)s:%(line)s %(definition)s:\n %(message)s'
637+
template = '{filename}:{line} {definition}:\n {message}'
636638
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'
638640
elif self.source and not self.explain:
639-
template += '\n\n%(lines)s\n'
641+
template += '\n\n{lines}\n'
640642
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
643645
['filename', 'line', 'definition', 'message',
644-
'explanation', 'lines'])
646+
'explanation', 'lines']))
645647

646648
__repr__ = __str__
647649

@@ -690,7 +692,7 @@ def to_rst(cls):
690692
for group in cls.groups:
691693
table += sep_line
692694
table += blank_line
693-
table += '|' + ('**%s**' % group.name).center(78) + '|\n'
695+
table += '|' + '**{0}**'.format(group.name).center(78) + '|\n'
694696
table += blank_line
695697
for error in group.errors:
696698
table += sep_line
@@ -710,17 +712,17 @@ def to_rst(cls):
710712

711713
D2xx = ErrorRegistry.create_group('D2', 'Whitespace Issues')
712714
D200 = D2xx.create_error('D200', 'One-line docstring should fit on one line '
713-
'with quotes', 'found %s')
715+
'with quotes', 'found {0}')
714716
D201 = D2xx.create_error('D201', 'No blank lines allowed before function '
715-
'docstring', 'found %s')
717+
'docstring', 'found {0}')
716718
D202 = D2xx.create_error('D202', 'No blank lines allowed after function '
717-
'docstring', 'found %s')
719+
'docstring', 'found {0}')
718720
D203 = D2xx.create_error('D203', '1 blank line required before class '
719-
'docstring', 'found %s')
721+
'docstring', 'found {0}')
720722
D204 = D2xx.create_error('D204', '1 blank line required after class '
721-
'docstring', 'found %s')
723+
'docstring', 'found {0}')
722724
D205 = D2xx.create_error('D205', '1 blank line required between summary line '
723-
'and description', 'found %s')
725+
'and description', 'found {0}')
724726
D206 = D2xx.create_error('D206', 'Docstring should be indented with spaces, '
725727
'not tabs')
726728
D207 = D2xx.create_error('D207', 'Docstring is under-indented')
@@ -730,27 +732,27 @@ def to_rst(cls):
730732
D210 = D2xx.create_error('D210', 'No whitespaces allowed surrounding '
731733
'docstring text')
732734
D211 = D2xx.create_error('D211', 'No blank lines allowed before class '
733-
'docstring', 'found %s')
735+
'docstring', 'found {0}')
734736
D212 = D2xx.create_error('D212', 'Multi-line docstring summary should start '
735737
'at the first line')
736738
D213 = D2xx.create_error('D213', 'Multi-line docstring summary should start '
737739
'at the second line')
738740

739741
D3xx = ErrorRegistry.create_group('D3', 'Quotes Issues')
740742
D300 = D3xx.create_error('D300', 'Use """triple double quotes"""',
741-
'found %s-quotes')
743+
'found {0}-quotes')
742744
D301 = D3xx.create_error('D301', 'Use r""" if any backslashes in a docstring')
743745
D302 = D3xx.create_error('D302', 'Use u""" for Unicode docstrings')
744746

745747
D4xx = ErrorRegistry.create_group('D4', 'Docstring Content Issues')
746748
D400 = D4xx.create_error('D400', 'First line should end with a period',
747-
'not %r')
749+
'not {0!r}')
748750
D401 = D4xx.create_error('D401', 'First line should be in imperative mood',
749-
'%r, not %r')
751+
'{0!r}, not {1!r}')
750752
D402 = D4xx.create_error('D402', 'First line should not be the function\'s '
751753
'"signature"')
752754
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}')
754756
D404 = D4xx.create_error('D404', 'First word of the docstring should not '
755757
'be `This`')
756758

@@ -1387,7 +1389,7 @@ def run_pydocstyle(use_pep257=False):
13871389
code = ReturnCode.no_violations_found
13881390
count = 0
13891391
for error in errors:
1390-
sys.stderr.write('%s\n' % error)
1392+
sys.stderr.write('{0}\n'.format(error))
13911393
code = ReturnCode.violations_found
13921394
count += 1
13931395
if run_conf.count:

0 commit comments

Comments
 (0)