Skip to content

Commit c9165cf

Browse files
committed
Fix format string usage.
This makes ruff happy, but it's unclear how we got into this situation to start with.
1 parent 544e58c commit c9165cf

70 files changed

Lines changed: 483 additions & 496 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

external/markdown-processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def repl(m):
5656
lexer = TextLexer()
5757
code = highlight(m.group(2), lexer, self.formatter)
5858
code = code.replace('\n\n', '\n&nbsp;\n').replace('\n', '<br />')
59-
return '\n\n<div class="code">%s</div>\n\n' % code
59+
return f'\n\n<div class="code">{code}</div>\n\n'
6060
joined_lines = "\n".join(lines)
6161
joined_lines = self.pattern.sub(repl, joined_lines)
6262
return joined_lines.split("\n")

external/moin-parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __init__(self, raw, request, **kw):
105105

106106
def format(self, formatter):
107107
codeid[0] += 1
108-
id = "pygments_%s" % codeid[0]
108+
id = f"pygments_{codeid[0]}"
109109
w = self.req.write
110110
w(formatter.code_area(1, id, start=1, step=1))
111111
w(formatter.rawHTML(highlight(self.raw, self.lexer, htmlformatter)))

pygments/cmdline.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ def _print_help(what, name):
6868
try:
6969
if what == 'lexer':
7070
cls = get_lexer_by_name(name)
71-
print("Help on the %s lexer:" % cls.name)
71+
print(f"Help on the {cls.name} lexer:")
7272
print(dedent(cls.__doc__))
7373
elif what == 'formatter':
7474
cls = find_formatter_class(name)
75-
print("Help on the %s formatter:" % cls.name)
75+
print(f"Help on the {cls.name} formatter:")
7676
print(dedent(cls.__doc__))
7777
elif what == 'filter':
7878
cls = find_filter_class(name)
79-
print("Help on the %s filter:" % name)
79+
print(f"Help on the {name} filter:")
8080
print(dedent(cls.__doc__))
8181
return 0
8282
except (AttributeError, ValueError):
83-
print("%s not found!" % what, file=sys.stderr)
83+
print(f"{what} not found!", file=sys.stderr)
8484
return 1
8585

8686

@@ -122,7 +122,7 @@ def _print_list(what):
122122
for name in get_all_filters():
123123
cls = find_filter_class(name)
124124
print("* " + name + ':')
125-
print(" %s" % docstring_headline(cls))
125+
print(f" {docstring_headline(cls)}")
126126

127127
elif what == 'style':
128128
print()
@@ -132,7 +132,7 @@ def _print_list(what):
132132
for name in get_all_styles():
133133
cls = get_style_by_name(name)
134134
print("* " + name + ':')
135-
print(" %s" % docstring_headline(cls))
135+
print(f" {docstring_headline(cls)}")
136136

137137

138138
def _print_list_as_json(requested_items):
@@ -185,8 +185,8 @@ def main_inner(parser, argns):
185185
return 0
186186

187187
if argns.V:
188-
print('Pygments version %s, (c) 2006-2024 by Georg Brandl, Matthäus '
189-
'Chajdas and contributors.' % __version__)
188+
print(f'Pygments version {__version__}, (c) 2006-2024 by Georg Brandl, Matthäus '
189+
'Chajdas and contributors.')
190190
return 0
191191

192192
def is_only_option(opt):
@@ -659,7 +659,7 @@ def main(args=sys.argv):
659659
msg = info[-1].strip()
660660
if len(info) >= 3:
661661
# extract relevant file and position info
662-
msg += '\n (f%s)' % info[-2].split('\n')[0].strip()[1:]
662+
msg += '\n (f{})'.format(info[-2].split('\n')[0].strip()[1:])
663663
print(file=sys.stderr)
664664
print('*** Error while highlighting:', file=sys.stderr)
665665
print(msg, file=sys.stderr)

pygments/filter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ class FunctionFilter(Filter):
6262

6363
def __init__(self, **options):
6464
if not hasattr(self, 'function'):
65-
raise TypeError('%r used without bound function' %
66-
self.__class__.__name__)
65+
raise TypeError(f'{self.__class__.__name__!r} used without bound function')
6766
Filter.__init__(self, **options)
6867

6968
def filter(self, lexer, stream):

pygments/filters/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_filter_by_name(filtername, **options):
3939
if cls:
4040
return cls(**options)
4141
else:
42-
raise ClassNotFound('filter %r not found' % filtername)
42+
raise ClassNotFound(f'filter {filtername!r} not found')
4343

4444

4545
def get_all_filters():
@@ -79,9 +79,9 @@ def __init__(self, **options):
7979
Filter.__init__(self, **options)
8080
tags = get_list_opt(options, 'codetags',
8181
['XXX', 'TODO', 'FIXME', 'BUG', 'NOTE'])
82-
self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
82+
self.tag_re = re.compile(r'\b({})\b'.format('|'.join([
8383
re.escape(tag) for tag in tags if tag
84-
]))
84+
])))
8585

8686
def filter(self, lexer, stream):
8787
regex = self.tag_re

pygments/formatters/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_formatter_by_name(_alias, **options):
7777
"""
7878
cls = find_formatter_class(_alias)
7979
if cls is None:
80-
raise ClassNotFound("no formatter found for name %r" % _alias)
80+
raise ClassNotFound(f"no formatter found for name {_alias!r}")
8181
return cls(**options)
8282

8383

@@ -112,7 +112,7 @@ def load_formatter_from_file(filename, formattername="CustomFormatter", **option
112112
except ClassNotFound:
113113
raise
114114
except Exception as err:
115-
raise ClassNotFound('error when loading custom formatter: %s' % err)
115+
raise ClassNotFound(f'error when loading custom formatter: {err}')
116116

117117

118118
def get_formatter_for_filename(fn, **options):
@@ -134,7 +134,7 @@ def get_formatter_for_filename(fn, **options):
134134
for filename in cls.filenames:
135135
if _fn_matches(fn, filename):
136136
return cls(**options)
137-
raise ClassNotFound("no formatter found for file name %r" % fn)
137+
raise ClassNotFound(f"no formatter found for file name {fn!r}")
138138

139139

140140
class _automodule(types.ModuleType):

pygments/formatters/bbcode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _make_styles(self):
6060
for ttype, ndef in self.style:
6161
start = end = ''
6262
if ndef['color']:
63-
start += '[color=#%s]' % ndef['color']
63+
start += '[color=#{}]'.format(ndef['color'])
6464
end = '[/color]' + end
6565
if ndef['bold']:
6666
start += '[b]'

pygments/formatters/groff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _make_styles(self):
6363
for ttype, ndef in self.style:
6464
start = end = ''
6565
if ndef['color']:
66-
start += '\\m[%s]' % ndef['color']
66+
start += '\\m[{}]'.format(ndef['color'])
6767
end = '\\m[]' + end
6868
if ndef['bold']:
6969
start += bold
@@ -72,7 +72,7 @@ def _make_styles(self):
7272
start += italic
7373
end = regular + end
7474
if ndef['bgcolor']:
75-
start += '\\M[%s]' % ndef['bgcolor']
75+
start += '\\M[{}]'.format(ndef['bgcolor'])
7676
end = '\\M[]' + end
7777

7878
self.styles[ttype] = start, end

pygments/formatters/html.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -488,17 +488,17 @@ def _create_stylesheet(self):
488488
name = self._get_css_class(ttype)
489489
style = ''
490490
if ndef['color']:
491-
style += 'color: %s; ' % webify(ndef['color'])
491+
style += 'color: {}; '.format(webify(ndef['color']))
492492
if ndef['bold']:
493493
style += 'font-weight: bold; '
494494
if ndef['italic']:
495495
style += 'font-style: italic; '
496496
if ndef['underline']:
497497
style += 'text-decoration: underline; '
498498
if ndef['bgcolor']:
499-
style += 'background-color: %s; ' % webify(ndef['bgcolor'])
499+
style += 'background-color: {}; '.format(webify(ndef['bgcolor']))
500500
if ndef['border']:
501-
style += 'border: 1px solid %s; ' % webify(ndef['border'])
501+
style += 'border: 1px solid {}; '.format(webify(ndef['border']))
502502
if style:
503503
t2c[ttype] = name
504504
# save len(ttype) to enable ordering the styles by
@@ -561,11 +561,11 @@ def get_background_style_defs(self, arg=None):
561561

562562
def get_linenos_style_defs(self):
563563
lines = [
564-
'pre { %s }' % self._pre_style,
565-
'td.linenos .normal { %s }' % self._linenos_style,
566-
'span.linenos { %s }' % self._linenos_style,
567-
'td.linenos .special { %s }' % self._linenos_special_style,
568-
'span.linenos.special { %s }' % self._linenos_special_style,
564+
f'pre {{ {self._pre_style} }}',
565+
f'td.linenos .normal {{ {self._linenos_style} }}',
566+
f'span.linenos {{ {self._linenos_style} }}',
567+
f'td.linenos .special {{ {self._linenos_special_style} }}',
568+
f'span.linenos.special {{ {self._linenos_special_style} }}',
569569
]
570570

571571
return lines
@@ -683,9 +683,9 @@ def _wrap_tablelinenos(self, inner):
683683

684684
if nocls:
685685
if special_line:
686-
style = ' style="%s"' % self._linenos_special_style
686+
style = f' style="{self._linenos_special_style}"'
687687
else:
688-
style = ' style="%s"' % self._linenos_style
688+
style = f' style="{self._linenos_style}"'
689689
else:
690690
if special_line:
691691
style = ' class="special"'
@@ -742,9 +742,9 @@ def _wrap_inlinelinenos(self, inner):
742742

743743
if nocls:
744744
if special_line:
745-
style = ' style="%s"' % self._linenos_special_style
745+
style = f' style="{self._linenos_special_style}"'
746746
else:
747-
style = ' style="%s"' % self._linenos_style
747+
style = f' style="{self._linenos_style}"'
748748
else:
749749
if special_line:
750750
style = ' class="linenos special"'
@@ -794,8 +794,8 @@ def _wrap_div(self, inner):
794794
style.append(self.cssstyles)
795795
style = '; '.join(style)
796796

797-
yield 0, ('<div' + (self.cssclass and ' class="%s"' % self.cssclass) +
798-
(style and (' style="%s"' % style)) + '>')
797+
yield 0, ('<div' + (self.cssclass and f' class="{self.cssclass}"') +
798+
(style and (f' style="{style}"')) + '>')
799799
yield from inner
800800
yield 0, '</div>\n'
801801

@@ -812,7 +812,7 @@ def _wrap_pre(self, inner):
812812

813813
# the empty span here is to keep leading empty lines from being
814814
# ignored by HTML parsers
815-
yield 0, ('<pre' + (style and ' style="%s"' % style) + '><span></span>')
815+
yield 0, ('<pre' + (style and f' style="{style}"') + '><span></span>')
816816
yield from inner
817817
yield 0, '</pre>'
818818

@@ -841,7 +841,7 @@ def _format_lines(self, tokensource):
841841
try:
842842
cspan = self.span_element_openers[ttype]
843843
except KeyError:
844-
title = ' title="%s"' % '.'.join(ttype) if self.debug_token_types else ''
844+
title = ' title="{}"'.format('.'.join(ttype)) if self.debug_token_types else ''
845845
if nocls:
846846
css_style = self._get_css_inline_styles(ttype)
847847
if css_style:
@@ -928,7 +928,7 @@ def _highlight_lines(self, tokensource):
928928
style = (f' style="background-color: {self.style.highlight_color}"')
929929
yield 1, f'<span{style}>{value}</span>'
930930
else:
931-
yield 1, '<span class="hll">%s</span>' % value
931+
yield 1, f'<span class="hll">{value}</span>'
932932
else:
933933
yield 1, value
934934

pygments/formatters/img.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ def _create_nix(self):
110110
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
111111
break
112112
else:
113-
raise FontNotFound('No usable fonts named: "%s"' %
114-
self.font_name)
113+
raise FontNotFound(f'No usable fonts named: "{self.font_name}"')
115114
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
116115
for stylename in STYLES[style]:
117116
path = self._get_nix_font_path(self.font_name, stylename)
@@ -142,8 +141,7 @@ def _create_mac(self):
142141
self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
143142
break
144143
else:
145-
raise FontNotFound('No usable fonts named: "%s"' %
146-
self.font_name)
144+
raise FontNotFound(f'No usable fonts named: "{self.font_name}"')
147145
for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
148146
for stylename in STYLES[style]:
149147
path = self._get_mac_font_path(font_map, self.font_name, stylename)

0 commit comments

Comments
 (0)