Skip to content

Commit

Permalink
Enable the FURB113 rule in Ruff (sphinx-doc#11856)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: danieleades <[email protected]>
  • Loading branch information
3 people authored Jan 21, 2024
1 parent f9c8943 commit 4f08cdf
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions doc/development/tutorials/examples/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 5 additions & 3 deletions sphinx/builders/latex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions sphinx/builders/texinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions sphinx/ext/inheritance_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions sphinx/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions sphinx/search/ja.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 2 additions & 5 deletions sphinx/util/cfamily.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4f08cdf

Please sign in to comment.