Skip to content

Commit 620e434

Browse files
authored
Improve string concatenation (#12758)
Use implicit concatenation over ``+``, and combine some implicit concatenations to a single string literal.
1 parent 18fbced commit 620e434

File tree

19 files changed

+80
-75
lines changed

19 files changed

+80
-75
lines changed

sphinx/domains/c/_parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,11 @@ def _parse_nested_name(self) -> ASTNestedName:
495495
self.fail("Expected identifier in nested name, "
496496
"got keyword: %s" % identifier)
497497
if self.matched_text in self.config.c_extra_keywords:
498-
msg = "Expected identifier, got user-defined keyword: %s." \
499-
+ " Remove it from c_extra_keywords to allow it as identifier.\n" \
500-
+ "Currently c_extra_keywords is %s."
498+
msg = (
499+
'Expected identifier, got user-defined keyword: %s.'
500+
' Remove it from c_extra_keywords to allow it as identifier.\n'
501+
'Currently c_extra_keywords is %s.'
502+
)
501503
self.fail(msg % (self.matched_text,
502504
str(self.config.c_extra_keywords)))
503505
ident = ASTIdentifier(identifier)
@@ -670,9 +672,11 @@ def _parse_declarator_name_suffix(
670672
self.fail("Expected identifier, "
671673
"got keyword: %s" % self.matched_text)
672674
if self.matched_text in self.config.c_extra_keywords:
673-
msg = "Expected identifier, got user-defined keyword: %s." \
674-
+ " Remove it from c_extra_keywords to allow it as identifier.\n" \
675-
+ "Currently c_extra_keywords is %s."
675+
msg = (
676+
'Expected identifier, got user-defined keyword: %s. '
677+
'Remove it from c_extra_keywords to allow it as identifier.\n'
678+
'Currently c_extra_keywords is %s.'
679+
)
676680
self.fail(msg % (self.matched_text,
677681
str(self.config.c_extra_keywords)))
678682
identifier = ASTIdentifier(self.matched_text)

sphinx/domains/cpp/_parser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ def _parse_decl_specs_simple(self, outer: str, typed: bool) -> ASTDeclSpecsSimpl
12631263
if self.skip_string('('):
12641264
expr = self._parse_constant_expression(inTemplate=False)
12651265
if not expr:
1266-
self.fail("Expected constant expression after '('" +
1266+
self.fail("Expected constant expression after '('"
12671267
" in explicit specifier.")
12681268
self.skip_ws()
12691269
if not self.skip_string(')'):
@@ -1972,13 +1972,14 @@ def _check_template_consistency(self, nestedName: ASTNestedName,
19721972
if numArgs > numParams:
19731973
numExtra = numArgs - numParams
19741974
if not fullSpecShorthand and not isMemberInstantiation:
1975-
msg = "Too many template argument lists compared to parameter" \
1976-
" lists. Argument lists: %d, Parameter lists: %d," \
1977-
" Extra empty parameters lists prepended: %d." \
1978-
% (numArgs, numParams, numExtra)
1979-
msg += " Declaration:\n\t"
1975+
msg = (
1976+
f'Too many template argument lists compared to parameter lists. '
1977+
f'Argument lists: {numArgs:d}, Parameter lists: {numParams:d}, '
1978+
f'Extra empty parameters lists prepended: {numExtra:d}. '
1979+
'Declaration:\n\t'
1980+
)
19801981
if templatePrefix:
1981-
msg += "%s\n\t" % templatePrefix
1982+
msg += f"{templatePrefix}\n\t"
19821983
msg += str(nestedName)
19831984
self.warn(msg)
19841985

sphinx/ext/apidoc.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def get_parser() -> argparse.ArgumentParser:
394394
'exclude_pattern',
395395
nargs='*',
396396
help=__(
397-
'fnmatch-style file and/or directory patterns ' 'to exclude from generation'
397+
'fnmatch-style file and/or directory patterns to exclude from generation'
398398
),
399399
)
400400

@@ -419,7 +419,7 @@ def get_parser() -> argparse.ArgumentParser:
419419
dest='maxdepth',
420420
type=int,
421421
default=4,
422-
help=__('maximum depth of submodules to show in the TOC ' '(default: 4)'),
422+
help=__('maximum depth of submodules to show in the TOC (default: 4)'),
423423
)
424424
parser.add_argument(
425425
'-f',
@@ -435,8 +435,7 @@ def get_parser() -> argparse.ArgumentParser:
435435
dest='followlinks',
436436
default=False,
437437
help=__(
438-
'follow symbolic links. Powerful when combined '
439-
'with collective.recipe.omelette.'
438+
'follow symbolic links. Powerful when combined with collective.recipe.omelette.'
440439
),
441440
)
442441
parser.add_argument(
@@ -490,15 +489,14 @@ def get_parser() -> argparse.ArgumentParser:
490489
'--module-first',
491490
action='store_true',
492491
dest='modulefirst',
493-
help=__('put module documentation before submodule ' 'documentation'),
492+
help=__('put module documentation before submodule documentation'),
494493
)
495494
parser.add_argument(
496495
'--implicit-namespaces',
497496
action='store_true',
498497
dest='implicit_namespaces',
499498
help=__(
500-
'interpret module paths according to PEP-0420 '
501-
'implicit namespaces specification'
499+
'interpret module paths according to PEP-0420 implicit namespaces specification'
502500
),
503501
)
504502
parser.add_argument(
@@ -559,7 +557,7 @@ def get_parser() -> argparse.ArgumentParser:
559557
action='store',
560558
dest='release',
561559
help=__(
562-
'project release, used when --full is given, ' 'defaults to --doc-version'
560+
'project release, used when --full is given, defaults to --doc-version'
563561
),
564562
)
565563

sphinx/ext/autosummary/generate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,23 +803,23 @@ def get_parser() -> argparse.ArgumentParser:
803803
action='store',
804804
dest='suffix',
805805
default='rst',
806-
help=__('default suffix for files (default: ' '%(default)s)'),
806+
help=__('default suffix for files (default: %(default)s)'),
807807
)
808808
parser.add_argument(
809809
'-t',
810810
'--templates',
811811
action='store',
812812
dest='templates',
813813
default=None,
814-
help=__('custom template directory (default: ' '%(default)s)'),
814+
help=__('custom template directory (default: %(default)s)'),
815815
)
816816
parser.add_argument(
817817
'-i',
818818
'--imported-members',
819819
action='store_true',
820820
dest='imported_members',
821821
default=False,
822-
help=__('document imported members (default: ' '%(default)s)'),
822+
help=__('document imported members (default: %(default)s)'),
823823
)
824824
parser.add_argument(
825825
'-a',

sphinx/ext/coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def write_py_coverage(self) -> None:
455455
if self.app.quiet or self.app.warningiserror:
456456
for meth in methods:
457457
logger.warning(
458-
__('undocumented python method:' +
458+
__('undocumented python method:'
459459
' %s :: %s :: %s'),
460460
name, class_name, meth)
461461
else:

sphinx/transforms/i18n.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def list_replace_or_append(lst: list[N], old: N, new: N) -> None:
202202
old_foot_refs = list(is_autofootnote_ref.findall(self.node))
203203
new_foot_refs = list(is_autofootnote_ref.findall(self.patch))
204204
self.compare_references(old_foot_refs, new_foot_refs,
205-
__('inconsistent footnote references in translated message.' +
205+
__('inconsistent footnote references in translated message.'
206206
' original: {0}, translated: {1}'))
207207
old_foot_namerefs: dict[str, list[nodes.footnote_reference]] = {}
208208
for r in old_foot_refs:
@@ -242,7 +242,7 @@ def update_refnamed_references(self) -> None:
242242
old_refs = list(is_refnamed_ref.findall(self.node))
243243
new_refs = list(is_refnamed_ref.findall(self.patch))
244244
self.compare_references(old_refs, new_refs,
245-
__('inconsistent references in translated message.' +
245+
__('inconsistent references in translated message.'
246246
' original: {0}, translated: {1}'))
247247
old_ref_names = [r['refname'] for r in old_refs]
248248
new_ref_names = [r['refname'] for r in new_refs]
@@ -267,7 +267,7 @@ def update_refnamed_footnote_references(self) -> None:
267267
new_foot_refs = list(is_refnamed_footnote_ref.findall(self.patch))
268268
refname_ids_map: dict[str, list[str]] = {}
269269
self.compare_references(old_foot_refs, new_foot_refs,
270-
__('inconsistent footnote references in translated message.' +
270+
__('inconsistent footnote references in translated message.'
271271
' original: {0}, translated: {1}'))
272272
for oldf in old_foot_refs:
273273
refname_ids_map.setdefault(oldf["refname"], []).append(oldf["ids"])
@@ -282,7 +282,7 @@ def update_citation_references(self) -> None:
282282
old_cite_refs = list(is_citation_ref.findall(self.node))
283283
new_cite_refs = list(is_citation_ref.findall(self.patch))
284284
self.compare_references(old_cite_refs, new_cite_refs,
285-
__('inconsistent citation references in translated message.' +
285+
__('inconsistent citation references in translated message.'
286286
' original: {0}, translated: {1}'))
287287
refname_ids_map: dict[str, list[str]] = {}
288288
for oldc in old_cite_refs:
@@ -299,7 +299,7 @@ def update_pending_xrefs(self) -> None:
299299
old_xrefs = [*self.node.findall(addnodes.pending_xref)]
300300
new_xrefs = [*self.patch.findall(addnodes.pending_xref)]
301301
self.compare_references(old_xrefs, new_xrefs,
302-
__('inconsistent term references in translated message.' +
302+
__('inconsistent term references in translated message.'
303303
' original: {0}, translated: {1}'))
304304

305305
xref_reftarget_map: dict[tuple[str, str, str] | None, dict[str, Any]] = {}

tests/test_builders/test_build_html_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def test_html_code_role(app):
4141
'<span class="k">pass</span>')
4242
assert ('<p>Inline <code class="code highlight python docutils literal highlight-python">' +
4343
common_content + '</code> code block</p>') in content
44-
assert ('<div class="highlight-python notranslate">' +
44+
assert ('<div class="highlight-python notranslate">'
4545
'<div class="highlight"><pre><span></span>' +
4646
common_content) in content

tests/test_builders/test_build_latex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ def test_latex_code_role(app):
16981698
r'\PYG{k}{pass}')
16991699
assert (r'Inline \sphinxcode{\sphinxupquote{%' + '\n' +
17001700
common_content + '%\n}} code block') in content
1701-
assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]' +
1701+
assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]'
17021702
'\n' + common_content + '\n' + r'\end{sphinxVerbatim}') in content
17031703

17041704

tests/test_builders/test_build_warnings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def _check_warnings(expected_warnings: str, warning: str) -> None:
4545
warnings = strip_colors(re.sub(re.escape(os.sep) + '{1,2}', '/', warning))
4646
assert re.match(f'{expected_warnings}$', warnings), (
4747
"Warnings don't match:\n"
48-
+ f'--- Expected (regex):\n{expected_warnings}\n'
49-
+ f'--- Got:\n{warnings}'
48+
f'--- Expected (regex):\n{expected_warnings}\n'
49+
f'--- Got:\n{warnings}'
5050
)
5151
sys.modules.pop('autodoc_fodder', None)
5252

tests/test_directives/test_directive_code.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ def test_code_block(app):
302302
assert len(code_block) > 0
303303
actual = code_block[0].text
304304
expect = (
305-
" def ruby?\n" +
306-
" false\n" +
305+
" def ruby?\n"
306+
" false\n"
307307
" end"
308308
)
309309
assert actual == expect
@@ -333,8 +333,8 @@ def test_code_block_caption_latex(app):
333333
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
334334
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}'
335335
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}'
336-
link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \
337-
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}'
336+
link = ('\\hyperref[\\detokenize{caption:name-test-rb}]'
337+
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}')
338338
assert caption in latex
339339
assert label in latex
340340
assert link in latex
@@ -345,12 +345,12 @@ def test_code_block_namedlink_latex(app):
345345
app.build(force_all=True)
346346
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
347347
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-rb}}}'
348-
link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\
349-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
348+
link1 = ('\\hyperref[\\detokenize{caption:name-test-rb}]'
349+
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}')
350350
label2 = ('\\def\\sphinxLiteralBlockLabel'
351351
'{\\label{\\detokenize{namedblocks:some-ruby-code}}}')
352-
link2 = '\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'\
353-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}'
352+
link2 = ('\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'
353+
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}')
354354
assert label1 in latex
355355
assert link1 in latex
356356
assert label2 in latex
@@ -453,8 +453,8 @@ def test_literalinclude_caption_latex(app):
453453
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
454454
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}'
455455
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}'
456-
link = '\\hyperref[\\detokenize{caption:name-test-py}]' \
457-
'{Listing \\ref{\\detokenize{caption:name-test-py}}}'
456+
link = ('\\hyperref[\\detokenize{caption:name-test-py}]'
457+
'{Listing \\ref{\\detokenize{caption:name-test-py}}}')
458458
assert caption in latex
459459
assert label in latex
460460
assert link in latex
@@ -465,12 +465,12 @@ def test_literalinclude_namedlink_latex(app):
465465
app.build(filenames='index')
466466
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
467467
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-py}}}'
468-
link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\
469-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
468+
link1 = ('\\hyperref[\\detokenize{caption:name-test-py}]'
469+
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}')
470470
label2 = ('\\def\\sphinxLiteralBlockLabel'
471471
'{\\label{\\detokenize{namedblocks:some-python-code}}}')
472-
link2 = '\\hyperref[\\detokenize{namedblocks:some-python-code}]'\
473-
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}'
472+
link2 = ('\\hyperref[\\detokenize{namedblocks:some-python-code}]'
473+
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}')
474474
assert label1 in latex
475475
assert link1 in latex
476476
assert label2 in latex

0 commit comments

Comments
 (0)