Enable the FURB113 rule in Ruff (#11856)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: danieleades <33452915+danieleades@users.noreply.github.com>
This commit is contained in:
Dimitri Papadopoulos Orfanos 2024-01-21 21:25:05 +01:00 committed by GitHub
parent f9c8943889
commit 4f08cdff13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 26 additions and 30 deletions

View File

@ -135,7 +135,7 @@ select = [
# refurb ('FURB') # refurb ('FURB')
# "FURB101", # `open` and `read` should be replaced by `Path({filename}).{suggestion}` # "FURB101", # `open` and `read` should be replaced by `Path({filename}).{suggestion}`
# "FURB105", # Unnecessary empty string passed to `print` # "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 "FURB118", # Use `operator.{operator}` instead of defining a function
"FURB131", # Prefer `clear` over deleting a full slice "FURB131", # Prefer `clear` over deleting a full slice
"FURB132", # Use `{suggestion}` instead of check and `remove` "FURB132", # Use `{suggestion}` instead of check and `remove`
@ -477,6 +477,8 @@ select = [
"doc/development/tutorials/examples/*" = ["INP001"] "doc/development/tutorials/examples/*" = ["INP001"]
# allow print() in the tutorial # allow print() in the tutorial
"doc/development/tutorials/examples/recipe.py" = ["T201"] "doc/development/tutorials/examples/recipe.py" = ["T201"]
"sphinx/domains/**" = ["FURB113"]
"tests/test_domains/test_domain_cpp.py" = ["FURB113"]
# from .flake8 # from .flake8
"sphinx/*" = ["E241"] "sphinx/*" = ["E241"]

View File

@ -107,8 +107,10 @@ def process_todo_nodes(app, doctree, fromdocname):
para += nodes.Text('.)') para += nodes.Text('.)')
# Insert into the todolist # Insert into the todolist
content.append(todo_info['todo']) content.extend((
content.append(para) todo_info['todo'],
para,
))
node.replace_self(content) node.replace_self(content)

View File

@ -375,9 +375,11 @@ class LaTeXBuilder(Builder):
newnodes: list[Node] = [nodes.emphasis(sectname, sectname)] newnodes: list[Node] = [nodes.emphasis(sectname, sectname)]
for subdir, title in self.titles: for subdir, title in self.titles:
if docname.startswith(subdir): if docname.startswith(subdir):
newnodes.append(nodes.Text(_(' (in '))) newnodes.extend((
newnodes.append(nodes.emphasis(title, title)) nodes.Text(_(' (in ')),
newnodes.append(nodes.Text(')')) nodes.emphasis(title, title),
nodes.Text(')'),
))
break break
else: else:
pass pass

View File

@ -166,9 +166,11 @@ class TexinfoBuilder(Builder):
newnodes: list[Node] = [nodes.emphasis(sectname, sectname)] newnodes: list[Node] = [nodes.emphasis(sectname, sectname)]
for subdir, title in self.titles: for subdir, title in self.titles:
if docname.startswith(subdir): if docname.startswith(subdir):
newnodes.append(nodes.Text(_(' (in '))) newnodes.extend((
newnodes.append(nodes.emphasis(title, title)) nodes.Text(_(' (in ')),
newnodes.append(nodes.Text(')')) nodes.emphasis(title, title),
nodes.Text(')'),
))
break break
else: else:
pass pass

View File

@ -307,9 +307,10 @@ class InheritanceGraph:
n_attrs.update(env.config.inheritance_node_attrs) n_attrs.update(env.config.inheritance_node_attrs)
e_attrs.update(env.config.inheritance_edge_attrs) e_attrs.update(env.config.inheritance_edge_attrs)
res: list[str] = [] res: list[str] = [
res.append('digraph %s {\n' % name) f'digraph {name} {{\n',
res.append(self._format_graph_attrs(g_attrs)) self._format_graph_attrs(g_attrs),
]
for name, fullname, bases, tooltip in sorted(self.class_info): for name, fullname, bases, tooltip in sorted(self.class_info):
# Write the node # Write the node

View File

@ -295,8 +295,7 @@ class EmphasizedLiteral(SphinxRole):
stack[-1] += "{" stack[-1] += "{"
else: else:
# start emphasis # start emphasis
stack.append('{') stack.extend(('{', ''))
stack.append('')
elif part == '}': elif part == '}':
if len(stack) == 3 and stack[1] == "{" and len(stack[2]) > 0: if len(stack) == 3 and stack[1] == "{" and len(stack[2]) > 0:
# emphasized word found # emphasized word found

View File

@ -418,17 +418,8 @@ class DefaultSplitter(BaseSplitter):
return [] return []
result = [] result = []
seg = ['B3', 'B2', 'B1'] seg = ['B3', 'B2', 'B1', *input, 'E1', 'E2', 'E3']
ctype = ['O', 'O', 'O'] ctype = ['O', 'O', 'O', *map(self.ctype_, input), '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')
word = seg[3] word = seg[3]
p1 = 'U' p1 = 'U'
p2 = 'U' p2 = 'U'

View File

@ -277,14 +277,11 @@ class BaseParser:
for e in errors: for e in errors:
if len(e[1]) > 0: if len(e[1]) > 0:
indent = ' ' indent = ' '
result.append(e[1]) result.extend((e[1], ':\n'))
result.append(':\n')
for line in str(e[0]).split('\n'): for line in str(e[0]).split('\n'):
if len(line) == 0: if len(line) == 0:
continue continue
result.append(indent) result.extend((indent, line, '\n'))
result.append(line)
result.append('\n')
else: else:
result.append(str(e[0])) result.append(str(e[0]))
return DefinitionError(''.join(result)) return DefinitionError(''.join(result))