Skip to content

Commit f7fbfaa

Browse files
Enable various pydocstyle (D) rules (#11878)
Co-authored-by: Adam Turner <[email protected]>
1 parent 587e011 commit f7fbfaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+301
-127
lines changed

.ruff.toml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,25 @@ select = [
7373
# "D107", # Missing docstring in `__init__`
7474
# "D200", # One-line docstring should fit on one line
7575
"D201", # No blank lines allowed before function docstring (found {num_lines})
76-
# "D202", # No blank lines allowed after function docstring (found {num_lines})
77-
# "D203", # 1 blank line required before class docstring
78-
# "D204", # 1 blank line required after class docstring
76+
"D202", # No blank lines allowed after function docstring (found {num_lines})
77+
"D204", # 1 blank line required after class docstring
7978
# "D205", # 1 blank line required between summary line and description
8079
"D206", # Docstring should be indented with spaces, not tabs
81-
# "D207", # Docstring is under-indented
82-
# "D208", # Docstring is over-indented
83-
# "D209", # Multi-line docstring closing quotes should be on a separate line
84-
# "D210", # No whitespaces allowed surrounding docstring text
80+
"D207", # Docstring is under-indented
81+
"D208", # Docstring is over-indented
82+
"D209", # Multi-line docstring closing quotes should be on a separate line
83+
"D210", # No whitespaces allowed surrounding docstring text
8584
"D211", # No blank lines allowed before class docstring
8685
# "D212", # Multi-line docstring summary should start at the first line
8786
# "D213", # Multi-line docstring summary should start at the second line
8887
# "D214", # Section is over-indented ("{name}")
8988
# "D215", # Section underline is over-indented ("{name}")
90-
# "D300", # Use triple double quotes `"""`
91-
# "D301", # Use `r"""` if any backslashes in a docstring
89+
"D300", # Use triple double quotes `"""`
90+
"D301", # Use `r"""` if any backslashes in a docstring
9291
# "D400", # First line should end with a period
9392
# "D401", # First line of docstring should be in imperative mood: "{first_line}"
94-
# "D402", # First line should not be the function's signature
95-
# "D403", # First word of the first line should be capitalized: `{}` -> `{}`
93+
"D402", # First line should not be the function's signature
94+
"D403", # First word of the first line should be capitalized: `{}` -> `{}`
9695
# "D404", # First word of the docstring should not be "This"
9796
"D405", # Section name should be properly capitalized ("{name}")
9897
# "D406", # Section name should end with a newline ("{name}")
@@ -499,9 +498,14 @@ select = [
499498
# Ruff bug: https://github.com/astral-sh/ruff/issues/6540
500499
"sphinx/transforms/i18n.py" = ["PGH004"]
501500

501+
# Function wrappers
502+
"sphinx/ext/autodoc/importer.py" = ["D402"]
503+
"sphinx/util/requests.py" = ["D402"]
504+
502505
"tests/*" = [
503506
"E501",
504507
"ANN", # tests don't need annotations
508+
"D402",
505509
"T201", # whitelist ``print`` for tests
506510
]
507511

doc/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ def parse_event(env, sig, signode):
210210

211211

212212
def linkify_issues_in_changelog(app, docname, source):
213-
""" Linkify issue references like #123 in changelog to GitHub. """
214-
213+
"""Linkify issue references like #123 in changelog to GitHub."""
215214
if docname == 'changes':
216215
changelog_path = os.path.join(os.path.dirname(__file__), "../CHANGES.rst")
217216
# this path trickery is needed because this script can

sphinx/addnodes.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def extract_original_messages(self) -> Sequence[str]:
7979

8080
class not_smartquotable:
8181
"""A node which does not support smart-quotes."""
82+
8283
support_smartquotes = False
8384

8485

@@ -163,6 +164,7 @@ class desc_signature(_desc_classes_injector, nodes.Part, nodes.Inline, nodes.Tex
163164
164165
This node always has the classes ``sig``, ``sig-object``, and the domain it belongs to.
165166
"""
167+
166168
# Note: the domain name is being added through a post-transform DescSigAddDomainAsClass
167169
classes = ['sig', 'sig-object']
168170

@@ -181,6 +183,7 @@ class desc_signature_line(nodes.Part, nodes.Inline, nodes.FixedTextElement):
181183
with ``is_multiline`` set to ``True``.
182184
Set ``add_permalink = True`` for the line that should get the permalink.
183185
"""
186+
184187
sphinx_line_type = ''
185188

186189

@@ -199,6 +202,7 @@ class desc_inline(_desc_classes_injector, nodes.Inline, nodes.TextElement):
199202
This node always has the classes ``sig``, ``sig-inline``,
200203
and the name of the domain it belongs to.
201204
"""
205+
202206
classes = ['sig', 'sig-inline']
203207

204208
def __init__(self, domain: str, *args: Any, **kwargs: Any) -> None:
@@ -219,6 +223,7 @@ class desc_name(_desc_classes_injector, nodes.Part, nodes.Inline, nodes.FixedTex
219223
220224
This node always has the class ``sig-name``.
221225
"""
226+
222227
classes = ['sig-name', 'descname'] # 'descname' is for backwards compatibility
223228

224229

@@ -230,6 +235,7 @@ class desc_addname(_desc_classes_injector, nodes.Part, nodes.Inline, nodes.Fixed
230235
231236
This node always has the class ``sig-prename``.
232237
"""
238+
233239
# 'descclassname' is for backwards compatibility
234240
classes = ['sig-prename', 'descclassname']
235241

@@ -256,6 +262,7 @@ class desc_parameterlist(nodes.Part, nodes.Inline, nodes.FixedTextElement):
256262
Set ``multi_line_parameter_list = True`` to describe a multi-line parameter list.
257263
In that case each parameter will then be written on its own, indented line.
258264
"""
265+
259266
child_text_separator = ', '
260267

261268
def astext(self) -> str:
@@ -269,6 +276,7 @@ class desc_type_parameter_list(nodes.Part, nodes.Inline, nodes.FixedTextElement)
269276
Set ``multi_line_parameter_list = True`` to describe a multi-line type parameters list.
270277
In that case each type parameter will then be written on its own, indented line.
271278
"""
279+
272280
child_text_separator = ', '
273281

274282
def astext(self) -> str:
@@ -285,6 +293,7 @@ class desc_type_parameter(nodes.Part, nodes.Inline, nodes.FixedTextElement):
285293

286294
class desc_optional(nodes.Part, nodes.Inline, nodes.FixedTextElement):
287295
"""Node for marking optional parts of the parameter list."""
296+
288297
child_text_separator = ', '
289298

290299
def astext(self) -> str:
@@ -315,6 +324,7 @@ class desc_annotation(nodes.Part, nodes.Inline, nodes.FixedTextElement):
315324

316325
class desc_sig_element(nodes.inline, _desc_classes_injector):
317326
"""Common parent class of nodes for inline text of a signature."""
327+
318328
classes: list[str] = []
319329

320330
def __init__(self, rawsource: str = '', text: str = '',
@@ -334,6 +344,7 @@ def __init_subclass__(cls, *, _sig_element: bool = False, **kwargs: Any):
334344

335345
class desc_sig_space(desc_sig_element, _sig_element=True):
336346
"""Node for a space in a signature."""
347+
337348
classes = ["w"]
338349

339350
def __init__(self, rawsource: str = '', text: str = ' ',
@@ -343,41 +354,49 @@ def __init__(self, rawsource: str = '', text: str = ' ',
343354

344355
class desc_sig_name(desc_sig_element, _sig_element=True):
345356
"""Node for an identifier in a signature."""
357+
346358
classes = ["n"]
347359

348360

349361
class desc_sig_operator(desc_sig_element, _sig_element=True):
350362
"""Node for an operator in a signature."""
363+
351364
classes = ["o"]
352365

353366

354367
class desc_sig_punctuation(desc_sig_element, _sig_element=True):
355368
"""Node for punctuation in a signature."""
369+
356370
classes = ["p"]
357371

358372

359373
class desc_sig_keyword(desc_sig_element, _sig_element=True):
360374
"""Node for a general keyword in a signature."""
375+
361376
classes = ["k"]
362377

363378

364379
class desc_sig_keyword_type(desc_sig_element, _sig_element=True):
365380
"""Node for a keyword which is a built-in type in a signature."""
381+
366382
classes = ["kt"]
367383

368384

369385
class desc_sig_literal_number(desc_sig_element, _sig_element=True):
370386
"""Node for a numeric literal in a signature."""
387+
371388
classes = ["m"]
372389

373390

374391
class desc_sig_literal_string(desc_sig_element, _sig_element=True):
375392
"""Node for a string literal in a signature."""
393+
376394
classes = ["s"]
377395

378396

379397
class desc_sig_literal_char(desc_sig_element, _sig_element=True):
380398
"""Node for a character literal in a signature."""
399+
381400
classes = ["sc"]
382401

383402

@@ -425,7 +444,7 @@ class index(nodes.Invisible, nodes.Inline, nodes.TextElement):
425444

426445

427446
class centered(nodes.Part, nodes.TextElement):
428-
"""This node is deprecated."""
447+
"""Deprecated."""
429448

430449

431450
class acks(nodes.Element):
@@ -479,6 +498,7 @@ class pending_xref(nodes.Inline, nodes.Element):
479498
These nodes are resolved before writing output, in
480499
BuildEnvironment.resolve_references.
481500
"""
501+
482502
child_text_separator = ''
483503

484504

sphinx/builders/_epub_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ def make_footnote(doc: nodes.document, label: str, uri: str) -> nodes.footnote:
317317
def footnote_spot(tree: nodes.document) -> tuple[Element, int]:
318318
"""Find or create a spot to place footnotes.
319319
320-
The function returns the tuple (parent, index)."""
320+
The function returns the tuple (parent, index).
321+
"""
321322
# The code uses the following heuristic:
322323
# a) place them after the last existing footnote
323324
# b) place them after an (empty) Footnotes rubric
@@ -480,7 +481,6 @@ def content_metadata(self) -> dict[str, Any]:
480481
"""Create a dictionary with all metadata for the content.opf
481482
file properly escaped.
482483
"""
483-
484484
if (source_date_epoch := os.getenv('SOURCE_DATE_EPOCH')) is not None:
485485
time_tuple = time.gmtime(int(source_date_epoch))
486486
else:

sphinx/builders/changes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ChangesBuilder(Builder):
2626
"""
2727
Write a summary with all versionadded/changed directives.
2828
"""
29+
2930
name = 'changes'
3031
epilog = __('The overview file is in %(outdir)s.')
3132

sphinx/builders/dirhtml.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class DirectoryHTMLBuilder(StandaloneHTMLBuilder):
2121
a directory given by their pagename, so that generated URLs don't have
2222
``.html`` in them.
2323
"""
24+
2425
name = 'dirhtml'
2526

2627
def get_target_uri(self, docname: str, typ: str | None = None) -> str:

sphinx/builders/epub3.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Epub3Builder(_epub_base.EpubBuilder):
7575
and META-INF/container.xml. Afterwards, all necessary files are zipped to
7676
an epub file.
7777
"""
78+
7879
name = 'epub'
7980
epilog = __('The ePub file is in %(outdir)s.')
8081

@@ -240,7 +241,7 @@ def validate_config_values(app: Sphinx) -> None:
240241

241242

242243
def convert_epub_css_files(app: Sphinx, config: Config) -> None:
243-
"""This converts string styled epub_css_files to tuple styled one."""
244+
"""Convert string styled epub_css_files to tuple styled one."""
244245
epub_css_files: list[tuple[str, dict[str, Any]]] = []
245246
for entry in config.epub_css_files:
246247
if isinstance(entry, str):

sphinx/builders/gettext.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
class Message:
4141
"""An entry of translatable message."""
42+
4243
def __init__(self, text: str, locations: list[tuple[str, int]], uuids: list[str]):
4344
self.text = text
4445
self.locations = locations
@@ -119,6 +120,7 @@ class I18nTags(Tags):
119120
To translate all text inside of only nodes, this class
120121
always returns True value even if no tags are defined.
121122
"""
123+
122124
def eval_condition(self, condition: Any) -> bool:
123125
return True
124126

@@ -127,6 +129,7 @@ class I18nBuilder(Builder):
127129
"""
128130
General i18n builder.
129131
"""
132+
130133
name = 'i18n'
131134
versioning_method = 'text'
132135
use_message_catalog = False
@@ -212,6 +215,7 @@ class MessageCatalogBuilder(I18nBuilder):
212215
"""
213216
Builds gettext-style message catalogs (.pot files).
214217
"""
218+
215219
name = 'gettext'
216220
epilog = __('The message catalogs are in %(outdir)s.')
217221

sphinx/builders/html/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class StandaloneHTMLBuilder(Builder):
160160
"""
161161
Builds standalone HTML docs.
162162
"""
163+
163164
name = 'html'
164165
format = 'html'
165166
epilog = __('The HTML pages are in %(outdir)s.')
@@ -782,7 +783,7 @@ def to_relpath(f: str) -> str:
782783
path.join(self.srcdir, src), err)
783784

784785
def create_pygments_style_file(self) -> None:
785-
"""create a style file for pygments."""
786+
"""Create a style file for pygments."""
786787
with open(path.join(self.outdir, '_static', 'pygments.css'), 'w',
787788
encoding="utf-8") as f:
788789
f.write(self.highlighter.get_stylesheet())
@@ -863,7 +864,7 @@ def copy_static_files(self) -> None:
863864
logger.warning(__('cannot copy static file %r'), err)
864865

865866
def copy_extra_files(self) -> None:
866-
"""copy html_extra_path files."""
867+
"""Copy html_extra_path files."""
867868
try:
868869
with progress_message(__('copying extra files')):
869870
excluded = Matcher(self.config.exclude_patterns)
@@ -1169,7 +1170,7 @@ def dump_search_index(self) -> None:
11691170

11701171

11711172
def convert_html_css_files(app: Sphinx, config: Config) -> None:
1172-
"""This converts string styled html_css_files to tuple styled one."""
1173+
"""Convert string styled html_css_files to tuple styled one."""
11731174
html_css_files: list[tuple[str, dict]] = []
11741175
for entry in config.html_css_files:
11751176
if isinstance(entry, str):
@@ -1192,7 +1193,7 @@ def _format_modified_time(timestamp: float) -> str:
11921193

11931194

11941195
def convert_html_js_files(app: Sphinx, config: Config) -> None:
1195-
"""This converts string styled html_js_files to tuple styled one."""
1196+
"""Convert string styled html_js_files to tuple styled one."""
11961197
html_js_files: list[tuple[str, dict]] = []
11971198
for entry in config.html_js_files:
11981199
if isinstance(entry, str):

sphinx/builders/html/transforms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class KeyboardTransform(SphinxPostTransform):
3131
<literal class="kbd">
3232
x
3333
"""
34+
3435
default_priority = 400
3536
formats = ('html',)
3637
pattern = re.compile(r'(?<=.)(-|\+|\^|\s+)(?=.)')

0 commit comments

Comments
 (0)