Skip to content

Commit 2f1cd36

Browse files
committed
Enable the RUF015 lint in Ruff
1 parent 439bff9 commit 2f1cd36

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ select = [
231231
"RUF010", # Use explicit conversion flag
232232
# "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
233233
"RUF013", # PEP 484 prohibits implicit `Optional`
234-
# "RUF015", # Prefer `next({iterable})` over single element slice
234+
"RUF015", # Prefer `next({iterable})` over single element slice
235235
"RUF016", # Slice in indexed access to type `{value_type}` uses type `{index_type}` instead of an integer
236236
"RUF017", # Avoid quadratic list summation
237237
"RUF018", # Avoid assignment expressions in `assert` statements

tests/test_domains/test_domain_std.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,23 @@ def test_productionlist(app):
504504
ul = nodes[2]
505505
cases = []
506506
for li in list(ul):
507-
assert len(list(li)) == 1
508-
p = list(li)[0]
507+
li_list = list(li)
508+
assert len(li_list) == 1
509+
p = li_list[0]
509510
assert p.tag == 'p'
510511
text = str(p.text).strip(' :')
511-
assert len(list(p)) == 1
512-
a = list(p)[0]
512+
p_list = list(p)
513+
assert len(p_list) == 1
514+
a = p_list[0]
513515
assert a.tag == 'a'
514516
link = a.get('href')
515-
assert len(list(a)) == 1
516-
code = list(a)[0]
517+
a_list = list(a)
518+
assert len(a_list) == 1
519+
code = a_list[0]
517520
assert code.tag == 'code'
518-
assert len(list(code)) == 1
519-
span = list(code)[0]
521+
code_list = list(code)
522+
assert len(code_list) == 1
523+
span = code_list[0]
520524
assert span.tag == 'span'
521525
linkText = span.text.strip()
522526
cases.append((text, link, linkText))

tests/test_extensions/test_ext_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_build(app):
3939
)
4040
assert len(undoc_c) == 1
4141
# the key is the full path to the header file, which isn't testable
42-
assert list(undoc_c.values())[0] == {('function', 'Py_SphinxTest')}
42+
assert next(iter(undoc_c.values())) == {('function', 'Py_SphinxTest')}
4343

4444
assert 'autodoc_target' in undoc_py
4545
assert 'funcs' in undoc_py['autodoc_target']

tests/test_util/test_util_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_extract_messages_without_rawsource():
180180
document.append(p)
181181
_transform(document)
182182
assert_node_count(extract_messages(document), nodes.TextElement, 1)
183-
assert [m for n, m in extract_messages(document)][0], 'text sentence'
183+
assert next(m for n, m in extract_messages(document)), 'text sentence'
184184

185185

186186
def test_clean_astext():

0 commit comments

Comments
 (0)