Skip to content

Commit

Permalink
lint: typecheck docs/conf.py (#12697)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Aug 26, 2024
1 parent bf431ed commit 53f8edf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
23 changes: 15 additions & 8 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
import os
import re
import time
from typing import TYPE_CHECKING

from sphinx import __display_version__
from sphinx import __display_version__, addnodes
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment

if TYPE_CHECKING:
from pathlib import Path

from docutils import nodes

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

Expand Down Expand Up @@ -254,13 +262,10 @@

# -- Extension interface -------------------------------------------------------

from sphinx import addnodes # NoQA: E402
from sphinx.application import Sphinx # NoQA: E402, TCH001

_event_sig_re = re.compile(r'([a-zA-Z-]+)\s*\((.*)\)')


def parse_event(env, sig, signode):
def parse_event(_env: BuildEnvironment, sig: str, signode: nodes.Element) -> str:
m = _event_sig_re.match(sig)
if m is None:
signode += addnodes.desc_name(sig, sig)
Expand All @@ -275,11 +280,13 @@ def parse_event(env, sig, signode):
return name


def linkify_issues_in_changelog(app, path, docname, source):
def linkify_issues_in_changelog(
_app: Sphinx, _path: Path, docname: str, source: list[str]
) -> None:
"""Linkify issue references like #123 in changelog to GitHub."""
if docname == 'changes':

def linkify(match):
def linkify(match: re.Match[str]) -> str:
url = 'https://github.com/sphinx-doc/sphinx/issues/' + match[1]
return f'`{match[0]} <{url}>`_'

Expand Down Expand Up @@ -338,7 +345,7 @@ def setup(app: Sphinx) -> None:
app.connect('include-read', linkify_issues_in_changelog)
app.connect('build-finished', build_redirects)
fdesc = GroupedField(
'parameter', label='Parameters', names=['param'], can_collapse=True
'parameter', label='Parameters', names=('param',), can_collapse=True
)
app.add_object_type(
'event',
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ exclude = [
]

[tool.mypy]
files = ["sphinx", "utils", "tests"]
files = ["sphinx", "utils", "tests", "doc/conf.py"]
exclude = [
"tests/roots",
# tests/
Expand Down
2 changes: 1 addition & 1 deletion sphinx/ext/autodoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def merge_members_option(options: dict) -> None:

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

def cut_lines(pre: int, post: int = 0, what: str | None = None) -> Callable:
def cut_lines(pre: int, post: int = 0, what: str | list[str] | None = None) -> Callable:
"""Return a listener that removes the first *pre* and last *post*
lines of every docstring. If *what* is a sequence of strings,
only docstrings of a type in *what* will be processed.
Expand Down

0 comments on commit 53f8edf

Please sign in to comment.