Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve string concatenation #12758

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions sphinx/domains/c/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ def _parse_nested_name(self) -> ASTNestedName:
self.fail("Expected identifier in nested name, "
"got keyword: %s" % identifier)
if self.matched_text in self.config.c_extra_keywords:
msg = "Expected identifier, got user-defined keyword: %s." \
+ " Remove it from c_extra_keywords to allow it as identifier.\n" \
+ "Currently c_extra_keywords is %s."
msg = (
'Expected identifier, got user-defined keyword: %s.'
' Remove it from c_extra_keywords to allow it as identifier.\n'
'Currently c_extra_keywords is %s.'
)
self.fail(msg % (self.matched_text,
str(self.config.c_extra_keywords)))
ident = ASTIdentifier(identifier)
Expand Down Expand Up @@ -670,9 +672,11 @@ def _parse_declarator_name_suffix(
self.fail("Expected identifier, "
"got keyword: %s" % self.matched_text)
if self.matched_text in self.config.c_extra_keywords:
msg = "Expected identifier, got user-defined keyword: %s." \
+ " Remove it from c_extra_keywords to allow it as identifier.\n" \
+ "Currently c_extra_keywords is %s."
msg = (
'Expected identifier, got user-defined keyword: %s. '
'Remove it from c_extra_keywords to allow it as identifier.\n'
'Currently c_extra_keywords is %s.'
)
self.fail(msg % (self.matched_text,
str(self.config.c_extra_keywords)))
identifier = ASTIdentifier(self.matched_text)
Expand Down
15 changes: 8 additions & 7 deletions sphinx/domains/cpp/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,7 @@ def _parse_decl_specs_simple(self, outer: str, typed: bool) -> ASTDeclSpecsSimpl
if self.skip_string('('):
expr = self._parse_constant_expression(inTemplate=False)
if not expr:
self.fail("Expected constant expression after '('" +
self.fail("Expected constant expression after '('"
" in explicit specifier.")
self.skip_ws()
if not self.skip_string(')'):
Expand Down Expand Up @@ -1972,13 +1972,14 @@ def _check_template_consistency(self, nestedName: ASTNestedName,
if numArgs > numParams:
numExtra = numArgs - numParams
if not fullSpecShorthand and not isMemberInstantiation:
msg = "Too many template argument lists compared to parameter" \
" lists. Argument lists: %d, Parameter lists: %d," \
" Extra empty parameters lists prepended: %d." \
% (numArgs, numParams, numExtra)
msg += " Declaration:\n\t"
msg = (
f'Too many template argument lists compared to parameter lists. '
f'Argument lists: {numArgs:d}, Parameter lists: {numParams:d}, '
f'Extra empty parameters lists prepended: {numExtra:d}. '
'Declaration:\n\t'
)
if templatePrefix:
msg += "%s\n\t" % templatePrefix
msg += f"{templatePrefix}\n\t"
msg += str(nestedName)
self.warn(msg)

Expand Down
14 changes: 6 additions & 8 deletions sphinx/ext/apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def get_parser() -> argparse.ArgumentParser:
'exclude_pattern',
nargs='*',
help=__(
'fnmatch-style file and/or directory patterns ' 'to exclude from generation'
'fnmatch-style file and/or directory patterns to exclude from generation'
),
)

Expand All @@ -419,7 +419,7 @@ def get_parser() -> argparse.ArgumentParser:
dest='maxdepth',
type=int,
default=4,
help=__('maximum depth of submodules to show in the TOC ' '(default: 4)'),
help=__('maximum depth of submodules to show in the TOC (default: 4)'),
)
parser.add_argument(
'-f',
Expand All @@ -435,8 +435,7 @@ def get_parser() -> argparse.ArgumentParser:
dest='followlinks',
default=False,
help=__(
'follow symbolic links. Powerful when combined '
'with collective.recipe.omelette.'
'follow symbolic links. Powerful when combined with collective.recipe.omelette.'
),
)
parser.add_argument(
Expand Down Expand Up @@ -490,15 +489,14 @@ def get_parser() -> argparse.ArgumentParser:
'--module-first',
action='store_true',
dest='modulefirst',
help=__('put module documentation before submodule ' 'documentation'),
help=__('put module documentation before submodule documentation'),
)
parser.add_argument(
'--implicit-namespaces',
action='store_true',
dest='implicit_namespaces',
help=__(
'interpret module paths according to PEP-0420 '
'implicit namespaces specification'
'interpret module paths according to PEP-0420 implicit namespaces specification'
),
)
parser.add_argument(
Expand Down Expand Up @@ -559,7 +557,7 @@ def get_parser() -> argparse.ArgumentParser:
action='store',
dest='release',
help=__(
'project release, used when --full is given, ' 'defaults to --doc-version'
'project release, used when --full is given, defaults to --doc-version'
),
)

Expand Down
6 changes: 3 additions & 3 deletions sphinx/ext/autosummary/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,23 +803,23 @@ def get_parser() -> argparse.ArgumentParser:
action='store',
dest='suffix',
default='rst',
help=__('default suffix for files (default: ' '%(default)s)'),
help=__('default suffix for files (default: %(default)s)'),
)
parser.add_argument(
'-t',
'--templates',
action='store',
dest='templates',
default=None,
help=__('custom template directory (default: ' '%(default)s)'),
help=__('custom template directory (default: %(default)s)'),
)
parser.add_argument(
'-i',
'--imported-members',
action='store_true',
dest='imported_members',
default=False,
help=__('document imported members (default: ' '%(default)s)'),
help=__('document imported members (default: %(default)s)'),
)
parser.add_argument(
'-a',
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def write_py_coverage(self) -> None:
if self.app.quiet or self.app.warningiserror:
for meth in methods:
logger.warning(
__('undocumented python method:' +
__('undocumented python method:'
' %s :: %s :: %s'),
name, class_name, meth)
else:
Expand Down
10 changes: 5 additions & 5 deletions sphinx/transforms/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def list_replace_or_append(lst: list[N], old: N, new: N) -> None:
old_foot_refs = list(is_autofootnote_ref.findall(self.node))
new_foot_refs = list(is_autofootnote_ref.findall(self.patch))
self.compare_references(old_foot_refs, new_foot_refs,
__('inconsistent footnote references in translated message.' +
__('inconsistent footnote references in translated message.'
' original: {0}, translated: {1}'))
old_foot_namerefs: dict[str, list[nodes.footnote_reference]] = {}
for r in old_foot_refs:
Expand Down Expand Up @@ -242,7 +242,7 @@ def update_refnamed_references(self) -> None:
old_refs = list(is_refnamed_ref.findall(self.node))
new_refs = list(is_refnamed_ref.findall(self.patch))
self.compare_references(old_refs, new_refs,
__('inconsistent references in translated message.' +
__('inconsistent references in translated message.'
' original: {0}, translated: {1}'))
old_ref_names = [r['refname'] for r in old_refs]
new_ref_names = [r['refname'] for r in new_refs]
Expand All @@ -267,7 +267,7 @@ def update_refnamed_footnote_references(self) -> None:
new_foot_refs = list(is_refnamed_footnote_ref.findall(self.patch))
refname_ids_map: dict[str, list[str]] = {}
self.compare_references(old_foot_refs, new_foot_refs,
__('inconsistent footnote references in translated message.' +
__('inconsistent footnote references in translated message.'
' original: {0}, translated: {1}'))
for oldf in old_foot_refs:
refname_ids_map.setdefault(oldf["refname"], []).append(oldf["ids"])
Expand All @@ -282,7 +282,7 @@ def update_citation_references(self) -> None:
old_cite_refs = list(is_citation_ref.findall(self.node))
new_cite_refs = list(is_citation_ref.findall(self.patch))
self.compare_references(old_cite_refs, new_cite_refs,
__('inconsistent citation references in translated message.' +
__('inconsistent citation references in translated message.'
' original: {0}, translated: {1}'))
refname_ids_map: dict[str, list[str]] = {}
for oldc in old_cite_refs:
Expand All @@ -299,7 +299,7 @@ def update_pending_xrefs(self) -> None:
old_xrefs = [*self.node.findall(addnodes.pending_xref)]
new_xrefs = [*self.patch.findall(addnodes.pending_xref)]
self.compare_references(old_xrefs, new_xrefs,
__('inconsistent term references in translated message.' +
__('inconsistent term references in translated message.'
' original: {0}, translated: {1}'))

xref_reftarget_map: dict[tuple[str, str, str] | None, dict[str, Any]] = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_builders/test_build_html_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def test_html_code_role(app):
'<span class="k">pass</span>')
assert ('<p>Inline <code class="code highlight python docutils literal highlight-python">' +
common_content + '</code> code block</p>') in content
assert ('<div class="highlight-python notranslate">' +
assert ('<div class="highlight-python notranslate">'
'<div class="highlight"><pre><span></span>' +
common_content) in content
2 changes: 1 addition & 1 deletion tests/test_builders/test_build_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ def test_latex_code_role(app):
r'\PYG{k}{pass}')
assert (r'Inline \sphinxcode{\sphinxupquote{%' + '\n' +
common_content + '%\n}} code block') in content
assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]' +
assert (r'\begin{sphinxVerbatim}[commandchars=\\\{\}]'
'\n' + common_content + '\n' + r'\end{sphinxVerbatim}') in content


Expand Down
4 changes: 2 additions & 2 deletions tests/test_builders/test_build_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def _check_warnings(expected_warnings: str, warning: str) -> None:
warnings = strip_colors(re.sub(re.escape(os.sep) + '{1,2}', '/', warning))
assert re.match(f'{expected_warnings}$', warnings), (
"Warnings don't match:\n"
+ f'--- Expected (regex):\n{expected_warnings}\n'
+ f'--- Got:\n{warnings}'
f'--- Expected (regex):\n{expected_warnings}\n'
f'--- Got:\n{warnings}'
)
sys.modules.pop('autodoc_fodder', None)

Expand Down
28 changes: 14 additions & 14 deletions tests/test_directives/test_directive_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ def test_code_block(app):
assert len(code_block) > 0
actual = code_block[0].text
expect = (
" def ruby?\n" +
" false\n" +
" def ruby?\n"
" false\n"
" end"
)
assert actual == expect
Expand Down Expand Up @@ -333,8 +333,8 @@ def test_code_block_caption_latex(app):
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstyleemphasis{test} rb}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id1}}}'
link = '\\hyperref[\\detokenize{caption:name-test-rb}]' \
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}'
link = ('\\hyperref[\\detokenize{caption:name-test-rb}]'
'{Listing \\ref{\\detokenize{caption:name-test-rb}}}')
assert caption in latex
assert label in latex
assert link in latex
Expand All @@ -345,12 +345,12 @@ def test_code_block_namedlink_latex(app):
app.build(force_all=True)
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-rb}}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-rb}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}'
link1 = ('\\hyperref[\\detokenize{caption:name-test-rb}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Ruby}}')
label2 = ('\\def\\sphinxLiteralBlockLabel'
'{\\label{\\detokenize{namedblocks:some-ruby-code}}}')
link2 = '\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}'
link2 = ('\\hyperref[\\detokenize{namedblocks:some-ruby-code}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the ruby code}}}')
assert label1 in latex
assert link1 in latex
assert label2 in latex
Expand Down Expand Up @@ -453,8 +453,8 @@ def test_literalinclude_caption_latex(app):
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
caption = '\\sphinxSetupCaptionForVerbatim{caption \\sphinxstylestrong{test} py}'
label = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:id2}}}'
link = '\\hyperref[\\detokenize{caption:name-test-py}]' \
'{Listing \\ref{\\detokenize{caption:name-test-py}}}'
link = ('\\hyperref[\\detokenize{caption:name-test-py}]'
'{Listing \\ref{\\detokenize{caption:name-test-py}}}')
assert caption in latex
assert label in latex
assert link in latex
Expand All @@ -465,12 +465,12 @@ def test_literalinclude_namedlink_latex(app):
app.build(filenames='index')
latex = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
label1 = '\\def\\sphinxLiteralBlockLabel{\\label{\\detokenize{caption:name-test-py}}}'
link1 = '\\hyperref[\\detokenize{caption:name-test-py}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}'
link1 = ('\\hyperref[\\detokenize{caption:name-test-py}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{Python}}')
label2 = ('\\def\\sphinxLiteralBlockLabel'
'{\\label{\\detokenize{namedblocks:some-python-code}}}')
link2 = '\\hyperref[\\detokenize{namedblocks:some-python-code}]'\
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}'
link2 = ('\\hyperref[\\detokenize{namedblocks:some-python-code}]'
'{\\sphinxcrossref{\\DUrole{std,std-ref}{the python code}}}')
assert label1 in latex
assert link1 in latex
assert label2 in latex
Expand Down
4 changes: 2 additions & 2 deletions tests/test_directives/test_directive_object_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def test_object_description_sections(app):


def test_object_description_content_line_number(app):
text = (".. py:function:: foo(bar)\n" +
"\n" +
text = (".. py:function:: foo(bar)\n"
"\n"
" Some link here: :ref:`abc`\n")
doc = restructuredtext.parse(app, text)
xrefs = list(doc.findall(condition=addnodes.pending_xref))
Expand Down
14 changes: 7 additions & 7 deletions tests/test_domains/test_domain_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ def test_domain_cpp_ast_function_definitions():
check('function', 'bool namespaced::theclass::method(arg1, arg2)',
{1: "namespaced::theclass::method__arg1.arg2",
2: "N10namespaced8theclass6methodE4arg14arg2"})
x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
'foo, bar, std::string baz = "foobar, blah, bleh") const = 0'
x = ('std::vector<std::pair<std::string, int>> &module::test(register int '
'foo, bar, std::string baz = "foobar, blah, bleh") const = 0')
check('function', x, {1: "module::test__i.bar.ssC",
2: "NK6module4testEi3barNSt6stringE"})
check('function', 'void f(std::pair<A, B>)',
Expand Down Expand Up @@ -557,8 +557,8 @@ def test_domain_cpp_ast_function_definitions():
check('function', 'MyClass::pointer MyClass::operator->()',
{1: "MyClass::pointer-operator", 2: "N7MyClassptEv"})

x = 'std::vector<std::pair<std::string, int>> &module::test(register int ' \
'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0'
x = ('std::vector<std::pair<std::string, int>> &module::test(register int '
'foo, bar[n], std::string baz = "foobar, blah, bleh") const = 0')
check('function', x, {1: "module::test__i.barA.ssC",
2: "NK6module4testEiAn_3barNSt6stringE",
3: "NK6module4testEiA1n_3barNSt6stringE"})
Expand Down Expand Up @@ -920,12 +920,12 @@ def test_domain_cpp_ast_requires_clauses():
check('function', 'template<typename T> requires A && B || C and D void f()',
{4: 'I0EIQooaa1A1Baa1C1DE1fvv'})
check('function',
'template<typename T> requires R<T> ' +
'template<typename U> requires S<T> ' +
'template<typename T> requires R<T> '
'template<typename U> requires S<T> '
'void A<T>::f() requires B',
{4: 'I0EIQ1RI1TEEI0EIQaa1SI1TE1BEN1A1fEvv'})
check('function',
'template<template<typename T> requires R<T> typename X> ' +
'template<template<typename T> requires R<T> typename X> '
'void f()',
{2: 'II0EIQ1RI1TEE0E1fv', 4: 'II0EIQ1RI1TEE0E1fvv'})
check('type',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_domains/test_domain_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ def test_no_index_entry(app):


def test_module_content_line_number(app):
text = (".. js:module:: foo\n" +
"\n" +
text = (".. js:module:: foo\n"
"\n"
" Some link here: :ref:`abc`\n")
doc = restructuredtext.parse(app, text)
xrefs = list(doc.findall(condition=addnodes.pending_xref))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_domains/test_domain_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ def test_domain_py_python_maximum_signature_line_length_in_text(app):


def test_module_content_line_number(app):
text = (".. py:module:: foo\n" +
"\n" +
text = (".. py:module:: foo\n"
"\n"
" Some link here: :ref:`abc`\n")
doc = restructuredtext.parse(app, text)
xrefs = list(doc.findall(condition=addnodes.pending_xref))
Expand Down
14 changes: 8 additions & 6 deletions tests/test_extensions/test_ext_apidoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ def test_toc_all_references_should_exist_pep420_enabled(make_app, apidoc):
if not (outdir / filename).is_file():
missing_files.append(filename)

assert len(missing_files) == 0, \
'File(s) referenced in TOC not found: {}\n' \
'TOC:\n{}'.format(", ".join(missing_files), toc)
all_missing = ', '.join(missing_files)
assert len(missing_files) == 0, (
f'File(s) referenced in TOC not found: {all_missing}\nTOC:\n{toc}'
)


@pytest.mark.apidoc(
Expand Down Expand Up @@ -352,9 +353,10 @@ def test_toc_all_references_should_exist_pep420_disabled(make_app, apidoc):
if not (outdir / filename).is_file():
missing_files.append(filename)

assert len(missing_files) == 0, \
'File(s) referenced in TOC not found: {}\n' \
'TOC:\n{}'.format(", ".join(missing_files), toc)
all_missing = ', '.join(missing_files)
assert len(missing_files) == 0, (
f'File(s) referenced in TOC not found: {all_missing}\nTOC:\n{toc}'
)


def extract_toc(path):
Expand Down
Loading