diff --git a/.ruff.toml b/.ruff.toml index 97ba78e7e56..4bca08fc8a4 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -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 diff --git a/sphinx/builders/latex/transforms.py b/sphinx/builders/latex/transforms.py index b6d0439d18a..df478533770 100644 --- a/sphinx/builders/latex/transforms.py +++ b/sphinx/builders/latex/transforms.py @@ -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']) @@ -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( diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index 26ecb913a50..7c59b158e48 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -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 = [] diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 20f0cc0fdbb..cb07c0bf615 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -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, @@ -242,25 +242,25 @@ 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 @@ -268,7 +268,7 @@ def width(self) -> int: 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 diff --git a/tests/test_domains/test_domain_std.py b/tests/test_domains/test_domain_std.py index 993fa197af8..eb01c8e7093 100644 --- a/tests/test_domains/test_domain_std.py +++ b/tests/test_domains/test_domain_std.py @@ -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') @@ -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') @@ -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') diff --git a/tests/test_extensions/test_ext_doctest.py b/tests/test_extensions/test_ext_doctest.py index fc86ee47f5d..4cfbe69ddde 100644 --- a/tests/test_extensions/test_ext_doctest.py +++ b/tests/test_extensions/test_ext_doctest.py @@ -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}' diff --git a/tests/test_pycode/test_pycode.py b/tests/test_pycode/test_pycode.py index cc08ff62c11..2d5ec66d32f 100644 --- a/tests/test_pycode/test_pycode.py +++ b/tests/test_pycode/test_pycode.py @@ -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, @@ -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}