Skip to content

Commit

Permalink
Enable the RUF031 lint in Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Nov 30, 2024
1 parent d796a8a commit 19dfc3f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ select = [
"RUF028", # This suppression comment is invalid because {}
"RUF029", # Function `{name}` is declared `async`, but doesn't `await` or use `async` features.
"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
"RUF033", # `__post_init__` method with argument defaults
"RUF034", # Useless if-else condition
Expand Down
4 changes: 2 additions & 2 deletions sphinx/builders/latex/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def visit_footnote_reference(self, node: nodes.footnote_reference) -> None:
number = node.astext().strip()
docname = node['docname']
if (docname, number) in self.appeared:
footnote = self.appeared[(docname, number)]
footnote = self.appeared[docname, number]
footnote['referred'] = True

mark = footnotemark('', number, refid=node['refid'])
Expand All @@ -471,7 +471,7 @@ def visit_footnote_reference(self, node: nodes.footnote_reference) -> None:
node.replace_self(footnote)
footnote.walkabout(self)

self.appeared[(docname, number)] = footnote
self.appeared[docname, number] = footnote
raise nodes.SkipNode

def get_footnote_by_reference(
Expand Down
4 changes: 2 additions & 2 deletions sphinx/pycode/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ def add_variable_comment(self, name: str, comment: str) -> None:
qualname = self.get_qualname_for(name)
if qualname:
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:
qualname = self.get_qualname_for(name)
if qualname:
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:
final = []
Expand Down
16 changes: 8 additions & 8 deletions sphinx/writers/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def add_cell(self, height: int, width: int) -> None:
self.cell_id += 1
for col in range(width):
for row in range(height):
assert self.cells[(self.row + row, self.col + col)] == 0
self.cells[(self.row + row, self.col + col)] = self.cell_id
assert self.cells[self.row + row, self.col + col] == 0
self.cells[self.row + row, self.col + col] = self.cell_id

def cell(
self,
Expand All @@ -242,33 +242,33 @@ class TableCell:
"""Data of a cell in a table."""

def __init__(self, table: Table, row: int, col: int) -> None:
if table.cells[(row, col)] == 0:
if table.cells[row, col] == 0:
raise IndexError

self.table = table
self.cell_id = table.cells[(row, col)]
self.cell_id = table.cells[row, col]
self.row = row
self.col = col

# 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
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

@property
def width(self) -> int:
"""Returns the cell width."""
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
return width

@property
def height(self) -> int:
"""Returns the cell height."""
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
return height

Expand Down
8 changes: 4 additions & 4 deletions tests/test_domains/test_domain_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def test_cmdoption(app):
entries=[('pair', 'ls command line option; -l', 'cmdoption-ls-l', '', None)],
)
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')
Expand All @@ -441,7 +441,7 @@ def test_cmdoption_for_None(app):
entries=[('pair', 'command line option; -l', 'cmdoption-l', '', None)],
)
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')
Expand Down Expand Up @@ -481,8 +481,8 @@ def test_multiple_cmdoptions(app):
)
assert ('cmd', '-o') in domain.progoptions
assert ('cmd', '--output') in domain.progoptions
assert domain.progoptions[('cmd', '-o')] == ('index', 'cmdoption-cmd-o')
assert domain.progoptions[('cmd', '--output')] == ('index', 'cmdoption-cmd-o')
assert domain.progoptions['cmd', '-o'] == ('index', 'cmdoption-cmd-o')
assert domain.progoptions['cmd', '--output'] == ('index', 'cmdoption-cmd-o')


@pytest.mark.sphinx('html', testroot='productionlist')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extensions/test_ext_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_skipif(app):


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}'


Expand Down
20 changes: 10 additions & 10 deletions tests/test_pycode/test_pycode.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ def test_ModuleAnalyzer_find_attr_docs():
('Foo', 'attr8'),
('Foo', 'attr9'),
}
assert docs[('Foo', 'attr1')] == ['comment before attr1', '']
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', 'attr5')] == ['attribute comment for attr5', '']
assert docs[('Foo', 'attr6')] == ['this comment is ignored', '']
assert docs[('Foo', 'attr7')] == ['this comment is ignored', '']
assert docs[('Foo', 'attr8')] == ['attribute comment for attr8', '']
assert docs[('Foo', 'attr9')] == ['string after attr9', '']
assert docs['Foo', 'attr1'] == ['comment before attr1', '']
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', 'attr5'] == ['attribute comment for attr5', '']
assert docs['Foo', 'attr6'] == ['this comment is ignored', '']
assert docs['Foo', 'attr7'] == ['this comment is ignored', '']
assert docs['Foo', 'attr8'] == ['attribute comment for attr8', '']
assert docs['Foo', 'attr9'] == ['string after attr9', '']
assert analyzer.tagorder == {
'Foo': 0,
'Foo.__init__': 8,
Expand Down Expand Up @@ -189,5 +189,5 @@ def test_ModuleAnalyzer_find_attr_docs_for_posonlyargs_method():
analyzer = ModuleAnalyzer.for_string(code, 'module')
docs = analyzer.find_attr_docs()
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}

0 comments on commit 19dfc3f

Please sign in to comment.