diff --git a/.ruff.toml b/.ruff.toml index a000ff52cfe..580da1206b2 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -135,7 +135,7 @@ select = [ # refurb ('FURB') # "FURB101", # `open` and `read` should be replaced by `Path({filename}).{suggestion}` # "FURB105", # Unnecessary empty string passed to `print` -# "FURB113", # Use `{suggestion}` instead of repeatedly calling `{name}.append()` + "FURB113", # Use `{suggestion}` instead of repeatedly calling `{name}.append()` "FURB118", # Use `operator.{operator}` instead of defining a function "FURB131", # Prefer `clear` over deleting a full slice "FURB132", # Use `{suggestion}` instead of check and `remove` @@ -477,6 +477,8 @@ select = [ "doc/development/tutorials/examples/*" = ["INP001"] # allow print() in the tutorial "doc/development/tutorials/examples/recipe.py" = ["T201"] +"sphinx/domains/**" = ["FURB113"] +"tests/test_domains/test_domain_cpp.py" = ["FURB113"] # from .flake8 "sphinx/*" = ["E241"] diff --git a/doc/development/tutorials/examples/todo.py b/doc/development/tutorials/examples/todo.py index 15368f440f3..82edd12fa6e 100644 --- a/doc/development/tutorials/examples/todo.py +++ b/doc/development/tutorials/examples/todo.py @@ -107,8 +107,10 @@ def process_todo_nodes(app, doctree, fromdocname): para += nodes.Text('.)') # Insert into the todolist - content.append(todo_info['todo']) - content.append(para) + content.extend(( + todo_info['todo'], + para, + )) node.replace_self(content) diff --git a/sphinx/builders/latex/__init__.py b/sphinx/builders/latex/__init__.py index 4f51bb37452..ef18e3444ef 100644 --- a/sphinx/builders/latex/__init__.py +++ b/sphinx/builders/latex/__init__.py @@ -375,9 +375,11 @@ def assemble_doctree( newnodes: list[Node] = [nodes.emphasis(sectname, sectname)] for subdir, title in self.titles: if docname.startswith(subdir): - newnodes.append(nodes.Text(_(' (in '))) - newnodes.append(nodes.emphasis(title, title)) - newnodes.append(nodes.Text(')')) + newnodes.extend(( + nodes.Text(_(' (in ')), + nodes.emphasis(title, title), + nodes.Text(')'), + )) break else: pass diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py index 69d412de0aa..683dcf8e513 100644 --- a/sphinx/builders/texinfo.py +++ b/sphinx/builders/texinfo.py @@ -166,9 +166,11 @@ def assemble_doctree( newnodes: list[Node] = [nodes.emphasis(sectname, sectname)] for subdir, title in self.titles: if docname.startswith(subdir): - newnodes.append(nodes.Text(_(' (in '))) - newnodes.append(nodes.emphasis(title, title)) - newnodes.append(nodes.Text(')')) + newnodes.extend(( + nodes.Text(_(' (in ')), + nodes.emphasis(title, title), + nodes.Text(')'), + )) break else: pass diff --git a/sphinx/ext/inheritance_diagram.py b/sphinx/ext/inheritance_diagram.py index 64c7d4655bd..664c4d4444a 100644 --- a/sphinx/ext/inheritance_diagram.py +++ b/sphinx/ext/inheritance_diagram.py @@ -307,9 +307,10 @@ def generate_dot(self, name: str, urls: dict[str, str] | None = None, n_attrs.update(env.config.inheritance_node_attrs) e_attrs.update(env.config.inheritance_edge_attrs) - res: list[str] = [] - res.append('digraph %s {\n' % name) - res.append(self._format_graph_attrs(g_attrs)) + res: list[str] = [ + f'digraph {name} {{\n', + self._format_graph_attrs(g_attrs), + ] for name, fullname, bases, tooltip in sorted(self.class_info): # Write the node diff --git a/sphinx/roles.py b/sphinx/roles.py index 658c41021f3..9618f48a51a 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -295,8 +295,7 @@ def parse(self, text: str) -> list[Node]: stack[-1] += "{" else: # start emphasis - stack.append('{') - stack.append('') + stack.extend(('{', '')) elif part == '}': if len(stack) == 3 and stack[1] == "{" and len(stack[2]) > 0: # emphasized word found diff --git a/sphinx/search/ja.py b/sphinx/search/ja.py index f838c1d206b..18aa12f998d 100644 --- a/sphinx/search/ja.py +++ b/sphinx/search/ja.py @@ -418,17 +418,8 @@ def split(self, input: str) -> list[str]: return [] result = [] - seg = ['B3', 'B2', 'B1'] - ctype = ['O', 'O', 'O'] - for t in input: - seg.append(t) - ctype.append(self.ctype_(t)) - seg.append('E1') - seg.append('E2') - seg.append('E3') - ctype.append('O') - ctype.append('O') - ctype.append('O') + seg = ['B3', 'B2', 'B1', *input, 'E1', 'E2', 'E3'] + ctype = ['O', 'O', 'O', *map(self.ctype_, input), 'O', 'O', 'O'] word = seg[3] p1 = 'U' p2 = 'U' diff --git a/sphinx/util/cfamily.py b/sphinx/util/cfamily.py index 8feb82bccb3..ae035dbf224 100644 --- a/sphinx/util/cfamily.py +++ b/sphinx/util/cfamily.py @@ -277,14 +277,11 @@ def _make_multi_error(self, errors: list[Any], header: str) -> DefinitionError: for e in errors: if len(e[1]) > 0: indent = ' ' - result.append(e[1]) - result.append(':\n') + result.extend((e[1], ':\n')) for line in str(e[0]).split('\n'): if len(line) == 0: continue - result.append(indent) - result.append(line) - result.append('\n') + result.extend((indent, line, '\n')) else: result.append(str(e[0])) return DefinitionError(''.join(result))