mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Enable the RUF031 lint in Ruff
This commit is contained in:
parent
d796a8ae21
commit
19dfc3f5af
@ -246,7 +246,7 @@ select = [
|
|||||||
"RUF028", # This suppression comment is invalid because {}
|
"RUF028", # This suppression comment is invalid because {}
|
||||||
"RUF029", # Function `{name}` is declared `async`, but doesn't `await` or use `async` features.
|
"RUF029", # Function `{name}` is declared `async`, but doesn't `await` or use `async` features.
|
||||||
"RUF030", # `print()` expression in `assert` statement is likely unintentional
|
"RUF030", # `print()` expression in `assert` statement is likely unintentional
|
||||||
# "RUF031", # Use parentheses for tuples in subscripts.
|
"RUF031", # Use parentheses for tuples in subscripts.
|
||||||
"RUF032", # `Decimal()` called with float literal argument
|
"RUF032", # `Decimal()` called with float literal argument
|
||||||
"RUF033", # `__post_init__` method with argument defaults
|
"RUF033", # `__post_init__` method with argument defaults
|
||||||
"RUF034", # Useless if-else condition
|
"RUF034", # Useless if-else condition
|
||||||
|
@ -455,7 +455,7 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
|
|||||||
number = node.astext().strip()
|
number = node.astext().strip()
|
||||||
docname = node['docname']
|
docname = node['docname']
|
||||||
if (docname, number) in self.appeared:
|
if (docname, number) in self.appeared:
|
||||||
footnote = self.appeared[(docname, number)]
|
footnote = self.appeared[docname, number]
|
||||||
footnote['referred'] = True
|
footnote['referred'] = True
|
||||||
|
|
||||||
mark = footnotemark('', number, refid=node['refid'])
|
mark = footnotemark('', number, refid=node['refid'])
|
||||||
@ -471,7 +471,7 @@ class LaTeXFootnoteVisitor(nodes.NodeVisitor):
|
|||||||
node.replace_self(footnote)
|
node.replace_self(footnote)
|
||||||
footnote.walkabout(self)
|
footnote.walkabout(self)
|
||||||
|
|
||||||
self.appeared[(docname, number)] = footnote
|
self.appeared[docname, number] = footnote
|
||||||
raise nodes.SkipNode
|
raise nodes.SkipNode
|
||||||
|
|
||||||
def get_footnote_by_reference(
|
def get_footnote_by_reference(
|
||||||
|
@ -283,13 +283,13 @@ class VariableCommentPicker(ast.NodeVisitor):
|
|||||||
qualname = self.get_qualname_for(name)
|
qualname = self.get_qualname_for(name)
|
||||||
if qualname:
|
if qualname:
|
||||||
basename = '.'.join(qualname[:-1])
|
basename = '.'.join(qualname[:-1])
|
||||||
self.comments[(basename, name)] = comment
|
self.comments[basename, name] = comment
|
||||||
|
|
||||||
def add_variable_annotation(self, name: str, annotation: ast.AST) -> None:
|
def add_variable_annotation(self, name: str, annotation: ast.AST) -> None:
|
||||||
qualname = self.get_qualname_for(name)
|
qualname = self.get_qualname_for(name)
|
||||||
if qualname:
|
if qualname:
|
||||||
basename = '.'.join(qualname[:-1])
|
basename = '.'.join(qualname[:-1])
|
||||||
self.annotations[(basename, name)] = ast_unparse(annotation)
|
self.annotations[basename, name] = ast_unparse(annotation)
|
||||||
|
|
||||||
def is_final(self, decorators: list[ast.expr]) -> bool:
|
def is_final(self, decorators: list[ast.expr]) -> bool:
|
||||||
final = []
|
final = []
|
||||||
|
@ -215,8 +215,8 @@ class Table:
|
|||||||
self.cell_id += 1
|
self.cell_id += 1
|
||||||
for col in range(width):
|
for col in range(width):
|
||||||
for row in range(height):
|
for row in range(height):
|
||||||
assert self.cells[(self.row + row, self.col + col)] == 0
|
assert self.cells[self.row + row, self.col + col] == 0
|
||||||
self.cells[(self.row + row, self.col + col)] = self.cell_id
|
self.cells[self.row + row, self.col + col] = self.cell_id
|
||||||
|
|
||||||
def cell(
|
def cell(
|
||||||
self,
|
self,
|
||||||
@ -242,25 +242,25 @@ class TableCell:
|
|||||||
"""Data of a cell in a table."""
|
"""Data of a cell in a table."""
|
||||||
|
|
||||||
def __init__(self, table: Table, row: int, col: int) -> None:
|
def __init__(self, table: Table, row: int, col: int) -> None:
|
||||||
if table.cells[(row, col)] == 0:
|
if table.cells[row, col] == 0:
|
||||||
raise IndexError
|
raise IndexError
|
||||||
|
|
||||||
self.table = table
|
self.table = table
|
||||||
self.cell_id = table.cells[(row, col)]
|
self.cell_id = table.cells[row, col]
|
||||||
self.row = row
|
self.row = row
|
||||||
self.col = col
|
self.col = col
|
||||||
|
|
||||||
# adjust position for multirow/multicol cell
|
# adjust position for multirow/multicol cell
|
||||||
while table.cells[(self.row - 1, self.col)] == self.cell_id:
|
while table.cells[self.row - 1, self.col] == self.cell_id:
|
||||||
self.row -= 1
|
self.row -= 1
|
||||||
while table.cells[(self.row, self.col - 1)] == self.cell_id:
|
while table.cells[self.row, self.col - 1] == self.cell_id:
|
||||||
self.col -= 1
|
self.col -= 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def width(self) -> int:
|
def width(self) -> int:
|
||||||
"""Returns the cell width."""
|
"""Returns the cell width."""
|
||||||
width = 0
|
width = 0
|
||||||
while self.table.cells[(self.row, self.col + width)] == self.cell_id:
|
while self.table.cells[self.row, self.col + width] == self.cell_id:
|
||||||
width += 1
|
width += 1
|
||||||
return width
|
return width
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ class TableCell:
|
|||||||
def height(self) -> int:
|
def height(self) -> int:
|
||||||
"""Returns the cell height."""
|
"""Returns the cell height."""
|
||||||
height = 0
|
height = 0
|
||||||
while self.table.cells[(self.row + height, self.col)] == self.cell_id:
|
while self.table.cells[self.row + height, self.col] == self.cell_id:
|
||||||
height += 1
|
height += 1
|
||||||
return height
|
return height
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ def test_cmdoption(app):
|
|||||||
entries=[('pair', 'ls command line option; -l', 'cmdoption-ls-l', '', None)],
|
entries=[('pair', 'ls command line option; -l', 'cmdoption-ls-l', '', None)],
|
||||||
)
|
)
|
||||||
assert ('ls', '-l') in domain.progoptions
|
assert ('ls', '-l') in domain.progoptions
|
||||||
assert domain.progoptions[('ls', '-l')] == ('index', 'cmdoption-ls-l')
|
assert domain.progoptions['ls', '-l'] == ('index', 'cmdoption-ls-l')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='root')
|
@pytest.mark.sphinx('html', testroot='root')
|
||||||
@ -441,7 +441,7 @@ def test_cmdoption_for_None(app):
|
|||||||
entries=[('pair', 'command line option; -l', 'cmdoption-l', '', None)],
|
entries=[('pair', 'command line option; -l', 'cmdoption-l', '', None)],
|
||||||
)
|
)
|
||||||
assert (None, '-l') in domain.progoptions
|
assert (None, '-l') in domain.progoptions
|
||||||
assert domain.progoptions[(None, '-l')] == ('index', 'cmdoption-l')
|
assert domain.progoptions[None, '-l'] == ('index', 'cmdoption-l')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='root')
|
@pytest.mark.sphinx('html', testroot='root')
|
||||||
@ -481,8 +481,8 @@ def test_multiple_cmdoptions(app):
|
|||||||
)
|
)
|
||||||
assert ('cmd', '-o') in domain.progoptions
|
assert ('cmd', '-o') in domain.progoptions
|
||||||
assert ('cmd', '--output') in domain.progoptions
|
assert ('cmd', '--output') in domain.progoptions
|
||||||
assert domain.progoptions[('cmd', '-o')] == ('index', 'cmdoption-cmd-o')
|
assert domain.progoptions['cmd', '-o'] == ('index', 'cmdoption-cmd-o')
|
||||||
assert domain.progoptions[('cmd', '--output')] == ('index', 'cmdoption-cmd-o')
|
assert domain.progoptions['cmd', '--output'] == ('index', 'cmdoption-cmd-o')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='productionlist')
|
@pytest.mark.sphinx('html', testroot='productionlist')
|
||||||
|
@ -122,7 +122,7 @@ def test_skipif(app):
|
|||||||
|
|
||||||
|
|
||||||
def record(directive, part, should_skip):
|
def record(directive, part, should_skip):
|
||||||
recorded_calls[(directive, part, should_skip)] += 1
|
recorded_calls[directive, part, should_skip] += 1
|
||||||
return f'Recorded {directive} {part} {should_skip}'
|
return f'Recorded {directive} {part} {should_skip}'
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,15 +151,15 @@ def test_ModuleAnalyzer_find_attr_docs():
|
|||||||
('Foo', 'attr8'),
|
('Foo', 'attr8'),
|
||||||
('Foo', 'attr9'),
|
('Foo', 'attr9'),
|
||||||
}
|
}
|
||||||
assert docs[('Foo', 'attr1')] == ['comment before attr1', '']
|
assert docs['Foo', 'attr1'] == ['comment before attr1', '']
|
||||||
assert docs[('Foo', 'attr3')] == ['attribute comment for attr3', '']
|
assert docs['Foo', 'attr3'] == ['attribute comment for attr3', '']
|
||||||
assert docs[('Foo', 'attr4')] == ['long attribute comment', '']
|
assert docs['Foo', 'attr4'] == ['long attribute comment', '']
|
||||||
assert docs[('Foo', 'attr4')] == ['long attribute comment', '']
|
assert docs['Foo', 'attr4'] == ['long attribute comment', '']
|
||||||
assert docs[('Foo', 'attr5')] == ['attribute comment for attr5', '']
|
assert docs['Foo', 'attr5'] == ['attribute comment for attr5', '']
|
||||||
assert docs[('Foo', 'attr6')] == ['this comment is ignored', '']
|
assert docs['Foo', 'attr6'] == ['this comment is ignored', '']
|
||||||
assert docs[('Foo', 'attr7')] == ['this comment is ignored', '']
|
assert docs['Foo', 'attr7'] == ['this comment is ignored', '']
|
||||||
assert docs[('Foo', 'attr8')] == ['attribute comment for attr8', '']
|
assert docs['Foo', 'attr8'] == ['attribute comment for attr8', '']
|
||||||
assert docs[('Foo', 'attr9')] == ['string after attr9', '']
|
assert docs['Foo', 'attr9'] == ['string after attr9', '']
|
||||||
assert analyzer.tagorder == {
|
assert analyzer.tagorder == {
|
||||||
'Foo': 0,
|
'Foo': 0,
|
||||||
'Foo.__init__': 8,
|
'Foo.__init__': 8,
|
||||||
@ -189,5 +189,5 @@ def test_ModuleAnalyzer_find_attr_docs_for_posonlyargs_method():
|
|||||||
analyzer = ModuleAnalyzer.for_string(code, 'module')
|
analyzer = ModuleAnalyzer.for_string(code, 'module')
|
||||||
docs = analyzer.find_attr_docs()
|
docs = analyzer.find_attr_docs()
|
||||||
assert set(docs) == {('Foo', 'attr')}
|
assert set(docs) == {('Foo', 'attr')}
|
||||||
assert docs[('Foo', 'attr')] == ['attribute comment', '']
|
assert docs['Foo', 'attr'] == ['attribute comment', '']
|
||||||
assert analyzer.tagorder == {'Foo': 0, 'Foo.__init__': 1, 'Foo.attr': 2}
|
assert analyzer.tagorder == {'Foo': 0, 'Foo.__init__': 1, 'Foo.attr': 2}
|
||||||
|
Loading…
Reference in New Issue
Block a user