Enable the entire D category in Ruff

This commit is contained in:
Adam Turner
2025-01-14 15:55:02 +00:00
parent dbf62cd503
commit c4daa95c09
96 changed files with 310 additions and 706 deletions

View File

@@ -22,9 +22,7 @@ class CustomEx(Exception):
def _funky_classmethod(name, b, c, d, docstring=None):
"""
Generates a classmethod for a class from a template by filling out some arguments.
"""
"""Generates a classmethod for a class from a template by filling out some arguments."""
def template(cls, a, b, c, d=4, e=5, f=6):
return a, b, c, d, e, f
@@ -95,9 +93,7 @@ class CustomDict(dict): # NoQA: FURB189
def function(foo, *args, **kwds):
"""
Return spam.
"""
"""Return spam."""
pass

View File

@@ -1,6 +1,4 @@
"""
docsting of empty_all module.
"""
"""docsting of empty_all module."""
__all__ = []

View File

@@ -1,5 +1,4 @@
"""
Test case for #11387 corner case involving inherited
"""Test case for #11387 corner case involving inherited
members with type annotations on python 3.9 and earlier
"""

View File

@@ -1,6 +1,5 @@
def func():
"""
first line
"""first line
---
second line
---

View File

@@ -7,7 +7,7 @@
C.prop_attr1
C.prop_attr2
C.C2
"""
""" # NoQA: D212
def with_sentence():
@@ -41,8 +41,7 @@ module_attr = 1
class C:
"""
My C class
"""My C class
with class_attr attribute
"""
@@ -59,8 +58,7 @@ class C:
self.instance_attr = '42'
def _prop_attr_get(self):
"""
This is a function docstring
"""This is a function docstring
return value is string.
"""
@@ -76,9 +74,7 @@ class C:
"""
class C2:
"""
This is a nested inner class docstring
"""
"""This is a nested inner class docstring"""
def func(arg_, *args, **kwargs):

View File

@@ -1,6 +1,4 @@
"""
module with trailing underscores everywhere
"""
"""module with trailing underscores everywhere"""
class class_:

View File

@@ -1,4 +1 @@
"""
>>> 'dir/bar.py:2'
"""
""">>> 'dir/bar.py:2'"""

View File

@@ -1,5 +1 @@
"""
>>> 'foo.py:3'
"""
""">>> 'foo.py:3'"""

View File

@@ -1,6 +1,5 @@
def hello(x: int, *args: int, **kwargs: int) -> None:
"""
Parameters
"""Parameters
----------
x
X

View File

@@ -1,6 +1,4 @@
"""
submodule
"""
"""submodule"""
# raise RuntimeError('This module should not get imported')
@@ -10,23 +8,17 @@ def decorator(f):
@decorator
def func1(a, b):
"""
this is func1
"""
"""this is func1"""
return a, b
@decorator
class Class1:
"""
this is Class1
"""
"""this is Class1"""
class Class3:
"""
this is Class3
"""
"""this is Class3"""
class_attr = 42
"""this is the class attribute class_attr"""

View File

@@ -1,6 +1,6 @@
"""
submodule
"""
""" # NoQA: D212
raise RuntimeError('This module should not get imported') # NoQA: EM101,TRY003
@@ -13,21 +13,17 @@ def decorator(f):
def func1(a, b):
"""
this is func1
"""
""" # NoQA: D212
return a, b
@decorator
class Class1:
"""
this is Class1
"""
"""this is Class1"""
class Class3:
"""
this is Class3
"""
"""this is Class3"""
class_attr = 42
"""this is the class attribute class_attr"""

View File

@@ -1,6 +1,4 @@
"""
mod1
"""
"""mod1"""
def decorator(f):
@@ -9,23 +7,17 @@ def decorator(f):
@decorator
def func1(a, b):
"""
this is func1
"""
"""this is func1"""
return a, b
@decorator
class Class1:
"""
this is Class1
"""
"""this is Class1"""
class Class3:
"""
this is Class3
"""
"""this is Class3"""
class_attr = 42
"""this is the class attribute class_attr"""

View File

@@ -1,6 +1,4 @@
"""
mod2
"""
"""mod2"""
def decorator(f):
@@ -9,14 +7,10 @@ def decorator(f):
@decorator
def func2(a, b):
"""
this is func2
"""
"""this is func2"""
return a, b
@decorator
class Class2:
"""
this is Class2
"""
"""this is Class2"""

View File

@@ -1,6 +1,4 @@
r"""
Test with a class diagram like this::
r"""Test with a class diagram like this::
A
/ \

View File

@@ -46,9 +46,7 @@ class CustomDataDescriptor2(CustomDataDescriptor):
def _funky_classmethod(name, b, c, d, docstring=None):
"""
Generates a classmethod for a class from a template by filling out some arguments.
"""
"""Generates a classmethod for a class from a template by filling out some arguments."""
def template(cls, a, b, c, d=4, e=5, f=6):
return a, b, c, d, e, f
@@ -136,9 +134,7 @@ class CustomDict(dict): # NoQA: FURB189
def function(foo, *args, **kwds):
"""
Return spam.
"""
"""Return spam."""
pass
@@ -216,9 +212,7 @@ class InstAttCls:
class EnumCls(enum.Enum):
"""
this is enum class
"""
"""this is enum class"""
#: doc for val1
val1 = 12

View File

@@ -1,6 +1,5 @@
class MarkupError:
"""
.. note:: This is a docstring with a
""".. note:: This is a docstring with a
small markup error which should have
correct location information.
"""

View File

@@ -11,8 +11,7 @@ LOCALTIME_2009 = type(LT)(LT_NEW)
@pytest.fixture
def no_source_date_year(monkeypatch):
"""
Explicitly clear SOURCE_DATE_EPOCH from the environment; this
"""Explicitly clear SOURCE_DATE_EPOCH from the environment; this
fixture can be used to ensure that copyright substitution logic
does not occur during selected test cases.
"""

View File

@@ -488,8 +488,7 @@ def custom_handler(
valid_credentials: tuple[str, str] | None = None,
success_criteria: Callable[[Any], bool] = lambda _: True,
) -> type[BaseHTTPRequestHandler]:
"""
Returns an HTTP request handler that authenticates the client and then determines
"""Returns an HTTP request handler that authenticates the client and then determines
an appropriate HTTP response code, based on caller-provided credentials and optional
success criteria, respectively.
"""

View File

@@ -7,8 +7,7 @@ module_level_var: int = 99
class PEP526NumpyClass:
"""
Sample class with PEP 526 annotations and numpy docstring
"""Sample class with PEP 526 annotations and numpy docstring
Attributes
----------

View File

@@ -243,8 +243,7 @@ def test_format_signature(app):
"""some docstring for F2."""
def __init__(self, *args, **kw):
"""
__init__(a1, a2, kw1=True, kw2=False)
"""__init__(a1, a2, kw1=True, kw2=False)
some docstring for __init__.
"""
@@ -363,9 +362,7 @@ def test_get_doc(app):
"""Docstring"""
def g():
"""
Docstring
"""
"""Docstring"""
for func in (f, g):
assert getdocl('function', func) == ['Docstring']

View File

@@ -13,9 +13,7 @@ from sphinx.ext.napoleon import Config, _process_docstring, _skip_member, setup
def simple_decorator(f):
"""
A simple decorator that does nothing, for tests to use.
"""
"""A simple decorator that does nothing, for tests to use."""
@functools.wraps(f)
def wrapper(*args, **kwargs):

View File

@@ -94,8 +94,7 @@ def test_todo_not_included(app):
confoverrides={'todo_include_todos': True},
)
def test_todo_valid_link(app):
"""
Test that the inserted "original entry" links for todo items have a target
"""Test that the inserted "original entry" links for todo items have a target
that exists in the LaTeX output. The target was previously incorrectly
omitted (GitHub issue #1020).
"""

View File

@@ -48,9 +48,10 @@ def check_viewcode_output(app: SphinxTestApp) -> str:
) in result
assert '<span>@decorator</span>\n' in result
assert f'<span>class</span>{sp}<span>Class1</span><span>:</span>\n' in result
assert '<span> </span><span>&quot;&quot;&quot;</span>\n' in result
assert '<span> this is Class1</span>\n' in result
assert '<span> &quot;&quot;&quot;</span>\n' in result
assert (
'<span> </span>'
'<span>&quot;&quot;&quot;this is Class1&quot;&quot;&quot;</span></div>\n'
) in result
return result

View File

@@ -9,8 +9,7 @@ import pytest
@pytest.mark.sphinx('dummy', testroot='metadata')
def test_docinfo(app):
"""
Inspect the 'docinfo' metadata stored in the first node of the document.
"""Inspect the 'docinfo' metadata stored in the first node of the document.
Note this doesn't give us access to data stored in subsequence blocks
that might be considered document metadata, such as 'abstract' or
'dedication' blocks, or the 'meta' role. Doing otherwise is probably more

View File

@@ -425,8 +425,7 @@ def test_search_index_is_deterministic(app):
def is_title_tuple_type(item: list[int | str]) -> bool:
"""
In the search index, titles inside .alltitles are stored as a tuple of
"""In the search index, titles inside .alltitles are stored as a tuple of
(document_idx, title_anchor). Tuples are represented as lists in JSON,
but their contents must not be sorted. We cannot sort them anyway, as
document_idx is an int and title_anchor is a str.

View File

@@ -943,9 +943,8 @@ def test_getdoc_inherited_classmethod():
class Foo:
@classmethod
def meth(cls):
"""
Docstring
indented text
"""Docstring
indented text
"""
class Bar(Foo):
@@ -961,9 +960,8 @@ def test_getdoc_inherited_classmethod():
def test_getdoc_inherited_decorated_method():
class Foo:
def meth(self):
"""
Docstring
indented text
"""Docstring
indented text
"""
class Bar(Foo):

View File

@@ -161,8 +161,7 @@ def test_extract_messages(rst, node_cls, count):
def test_extract_messages_without_rawsource():
"""
Check node.rawsource is fall-backed by using node.astext() value.
"""Check node.rawsource is fall-backed by using node.astext() value.
`extract_message` which is used from Sphinx i18n feature drop ``not node.rawsource``
nodes. So, all nodes which want to translate must have ``rawsource`` value.

View File

@@ -28,8 +28,7 @@ CERT_FILE: Final[str] = str(TESTS_ROOT / 'certs' / 'cert.pem')
class HttpServerThread(Thread):
def __init__(self, handler: type[BaseRequestHandler], *, port: int = 0) -> None:
"""
Constructs a threaded HTTP server. The default port number of ``0``
"""Constructs a threaded HTTP server. The default port number of ``0``
delegates selection of a port number to bind to to Python.
Ref: https://docs.python.org/3.11/library/socketserver.html#asynchronous-mixins
@@ -77,8 +76,7 @@ def http_server(
@contextmanager
def rewrite_hyperlinks(app: Sphinx, server: HTTPServer) -> Iterator[None]:
"""
Rewrite hyperlinks that refer to network location 'localhost:7777',
"""Rewrite hyperlinks that refer to network location 'localhost:7777',
allowing that location to vary dynamically with the arbitrary test HTTP
server port assigned during unit testing.
@@ -109,8 +107,7 @@ def serve_application(
tls_enabled: bool = False,
port: int = 0,
) -> Iterator[str]:
"""
Prepare a temporary server to handle HTTP requests related to the links
"""Prepare a temporary server to handle HTTP requests related to the links
found in a Sphinx application project.
:param app: The Sphinx application.