Skip to content

Commit 341b041

Browse files
authored
fixup! "lint: typecheck docs/conf.py (#12697)" (#12933)
1 parent 702ba34 commit 341b041

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

doc/conf.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66
import time
77
from typing import TYPE_CHECKING
88

9-
from sphinx import __display_version__, addnodes
10-
from sphinx.application import Sphinx
11-
from sphinx.environment import BuildEnvironment
12-
13-
if TYPE_CHECKING:
14-
from pathlib import Path
15-
16-
from docutils import nodes
9+
from sphinx import __display_version__
1710

1811
os.environ['SPHINX_AUTODOC_RELOAD_MODULES'] = '1'
1912

@@ -263,10 +256,20 @@
263256

264257
# -- Extension interface -------------------------------------------------------
265258

259+
from sphinx import addnodes # NoQA: E402
260+
261+
if TYPE_CHECKING:
262+
from pathlib import Path
263+
264+
from docutils.nodes import Element
265+
266+
from sphinx.application import Sphinx
267+
from sphinx.environment import BuildEnvironment
268+
266269
_event_sig_re = re.compile(r'([a-zA-Z-]+)\s*\((.*)\)')
267270

268271

269-
def parse_event(_env: BuildEnvironment, sig: str, signode: nodes.Element) -> str:
272+
def parse_event(_env: BuildEnvironment, sig: str, signode: Element) -> str:
270273
m = _event_sig_re.match(sig)
271274
if m is None:
272275
signode += addnodes.desc_name(sig, sig)

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ exclude = [
137137
]
138138

139139
[tool.mypy]
140-
files = ["sphinx", "utils", "tests", "doc/conf.py"]
140+
files = [
141+
"doc/conf.py",
142+
"sphinx",
143+
"tests",
144+
"utils",
145+
]
141146
exclude = [
142147
"tests/roots",
143148
# tests/

sphinx/ext/autodoc/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,23 @@ def merge_members_option(options: dict) -> None:
177177

178178
# Some useful event listener factories for autodoc-process-docstring.
179179

180-
def cut_lines(pre: int, post: int = 0, what: str | list[str] | None = None) -> Callable:
180+
def cut_lines(pre: int, post: int = 0, what: Sequence[str] | None = None) -> Callable:
181181
"""Return a listener that removes the first *pre* and last *post*
182182
lines of every docstring. If *what* is a sequence of strings,
183183
only docstrings of a type in *what* will be processed.
184184
185185
Use like this (e.g. in the ``setup()`` function of :file:`conf.py`)::
186186
187187
from sphinx.ext.autodoc import cut_lines
188-
app.connect('autodoc-process-docstring', cut_lines(4, what=['module']))
188+
app.connect('autodoc-process-docstring', cut_lines(4, what={'module'}))
189189
190190
This can (and should) be used in place of :confval:`automodule_skip_lines`.
191191
"""
192+
what_unique = frozenset(what or ())
193+
192194
def process(app: Sphinx, what_: str, name: str, obj: Any, options: Any, lines: list[str],
193195
) -> None:
194-
if what and what_ not in what:
196+
if what_ not in what_unique:
195197
return
196198
del lines[:pre]
197199
if post:

0 commit comments

Comments
 (0)