Enable the RUF015 lint in Ruff

This commit is contained in:
Adam Turner 2024-11-30 19:19:34 +00:00
parent 439bff92c7
commit 2f1cd36798
4 changed files with 15 additions and 11 deletions

View File

@ -231,7 +231,7 @@ select = [
"RUF010", # Use explicit conversion flag "RUF010", # Use explicit conversion flag
# "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar` # "RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"RUF013", # PEP 484 prohibits implicit `Optional` "RUF013", # PEP 484 prohibits implicit `Optional`
# "RUF015", # Prefer `next({iterable})` over single element slice "RUF015", # Prefer `next({iterable})` over single element slice
"RUF016", # Slice in indexed access to type `{value_type}` uses type `{index_type}` instead of an integer "RUF016", # Slice in indexed access to type `{value_type}` uses type `{index_type}` instead of an integer
"RUF017", # Avoid quadratic list summation "RUF017", # Avoid quadratic list summation
"RUF018", # Avoid assignment expressions in `assert` statements "RUF018", # Avoid assignment expressions in `assert` statements

View File

@ -504,19 +504,23 @@ def test_productionlist(app):
ul = nodes[2] ul = nodes[2]
cases = [] cases = []
for li in list(ul): for li in list(ul):
assert len(list(li)) == 1 li_list = list(li)
p = list(li)[0] assert len(li_list) == 1
p = li_list[0]
assert p.tag == 'p' assert p.tag == 'p'
text = str(p.text).strip(' :') text = str(p.text).strip(' :')
assert len(list(p)) == 1 p_list = list(p)
a = list(p)[0] assert len(p_list) == 1
a = p_list[0]
assert a.tag == 'a' assert a.tag == 'a'
link = a.get('href') link = a.get('href')
assert len(list(a)) == 1 a_list = list(a)
code = list(a)[0] assert len(a_list) == 1
code = a_list[0]
assert code.tag == 'code' assert code.tag == 'code'
assert len(list(code)) == 1 code_list = list(code)
span = list(code)[0] assert len(code_list) == 1
span = code_list[0]
assert span.tag == 'span' assert span.tag == 'span'
linkText = span.text.strip() linkText = span.text.strip()
cases.append((text, link, linkText)) cases.append((text, link, linkText))

View File

@ -39,7 +39,7 @@ def test_build(app):
) )
assert len(undoc_c) == 1 assert len(undoc_c) == 1
# the key is the full path to the header file, which isn't testable # the key is the full path to the header file, which isn't testable
assert list(undoc_c.values())[0] == {('function', 'Py_SphinxTest')} assert next(iter(undoc_c.values())) == {('function', 'Py_SphinxTest')}
assert 'autodoc_target' in undoc_py assert 'autodoc_target' in undoc_py
assert 'funcs' in undoc_py['autodoc_target'] assert 'funcs' in undoc_py['autodoc_target']

View File

@ -180,7 +180,7 @@ def test_extract_messages_without_rawsource():
document.append(p) document.append(p)
_transform(document) _transform(document)
assert_node_count(extract_messages(document), nodes.TextElement, 1) assert_node_count(extract_messages(document), nodes.TextElement, 1)
assert [m for n, m in extract_messages(document)][0], 'text sentence' assert next(m for n, m in extract_messages(document)), 'text sentence'
def test_clean_astext(): def test_clean_astext():