Shrink the mypy whitelist: `sphinx.application` (#12568)

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
danieleades
2024-07-15 03:04:10 +01:00
committed by GitHub
parent 3456ff3ca3
commit f4bb9ca112
4 changed files with 19 additions and 14 deletions

View File

@@ -180,12 +180,14 @@ nitpick_ignore = {
('js:func', 'string'),
('py:attr', 'srcline'),
('py:class', 'Element'), # sphinx.domains.Domain
('py:class', 'Documenter'), # sphinx.application.Sphinx.add_autodocumenter
('py:class', 'IndexEntry'), # sphinx.domains.IndexEntry
('py:class', 'Node'), # sphinx.domains.Domain
('py:class', 'NullTranslations'), # gettext.NullTranslations
('py:class', 'RoleFunction'), # sphinx.domains.Domain
('py:class', 'RSTState'), # sphinx.utils.parsing.nested_parse_to_nodes
('py:class', 'Theme'), # sphinx.application.TemplateBridge
('py:class', 'SearchLanguage'), # sphinx.application.Sphinx.add_search_language
('py:class', 'StringList'), # sphinx.utils.parsing.nested_parse_to_nodes
('py:class', 'system_message'), # sphinx.utils.docutils.SphinxDirective
('py:class', 'TitleGetter'), # sphinx.domains.Domain

View File

@@ -271,7 +271,6 @@ module = [
"sphinx.search",
"sphinx.testing.fixtures",
"sphinx.testing.path",
"sphinx.testing.util",
"sphinx.util",
"sphinx.util.display",
"sphinx.util.docfields",

View File

@@ -42,14 +42,16 @@ from sphinx.util.tags import Tags
if TYPE_CHECKING:
from docutils import nodes
from docutils.nodes import Element
from docutils.nodes import Element, Node
from docutils.parsers import Parser
from sphinx.builders import Builder
from sphinx.domains import Domain, Index
from sphinx.environment.collectors import EnvironmentCollector
from sphinx.ext.autodoc import Documenter
from sphinx.extension import Extension
from sphinx.roles import XRefRole
from sphinx.search import SearchLanguage
from sphinx.theming import Theme
from sphinx.util.typing import RoleFunction, TitleGetter
@@ -138,7 +140,7 @@ class Sphinx:
def __init__(self, srcdir: str | os.PathLike[str], confdir: str | os.PathLike[str] | None,
outdir: str | os.PathLike[str], doctreedir: str | os.PathLike[str],
buildername: str, confoverrides: dict | None = None,
status: IO | None = sys.stdout, warning: IO | None = sys.stderr,
status: IO[str] | None = sys.stdout, warning: IO[str] | None = sys.stderr,
freshenv: bool = False, warningiserror: bool = False,
tags: Sequence[str] = (),
verbosity: int = 0, parallel: int = 0, keep_going: bool = False,
@@ -190,14 +192,14 @@ class Sphinx:
self.parallel = parallel
if status is None:
self._status: IO = StringIO()
self._status: IO[str] = StringIO()
self.quiet: bool = True
else:
self._status = status
self.quiet = False
if warning is None:
self._warning: IO = StringIO()
self._warning: IO[str] = StringIO()
else:
self._warning = warning
self._warncount = 0
@@ -743,7 +745,10 @@ class Sphinx:
name, type='app', subtype='add_role')
docutils.register_role(name, role)
def add_generic_role(self, name: str, nodeclass: Any, override: bool = False) -> None:
def add_generic_role(
self, name: str, nodeclass: type[Node], override: bool = False
) -> None:
"""Register a generic Docutils role.
Register a Docutils role that does nothing but wrap its contents in the
@@ -820,7 +825,7 @@ class Sphinx:
"""
self.registry.add_role_to_domain(domain, name, role, override=override)
def add_index_to_domain(self, domain: str, index: type[Index], override: bool = False,
def add_index_to_domain(self, domain: str, index: type[Index], _override: bool = False,
) -> None:
"""Register a custom index for a domain.
@@ -1165,7 +1170,7 @@ class Sphinx:
logger.debug('[app] adding lexer: %r', (alias, lexer))
lexer_classes[alias] = lexer
def add_autodocumenter(self, cls: Any, override: bool = False) -> None:
def add_autodocumenter(self, cls: type[Documenter], override: bool = False) -> None:
"""Register a new documenter class for the autodoc extension.
Add *cls* as a new documenter class for the :mod:`sphinx.ext.autodoc`
@@ -1203,7 +1208,7 @@ class Sphinx:
logger.debug('[app] adding autodoc attrgetter: %r', (typ, getter))
self.registry.add_autodoc_attrgetter(typ, getter)
def add_search_language(self, cls: Any) -> None:
def add_search_language(self, cls: type[SearchLanguage]) -> None:
"""Register a new language for the HTML search index.
Add *cls*, which must be a subclass of
@@ -1215,8 +1220,7 @@ class Sphinx:
.. versionadded:: 1.1
"""
logger.debug('[app] adding search language: %r', cls)
from sphinx.search import SearchLanguage, languages
assert issubclass(cls, SearchLanguage)
from sphinx.search import languages
languages[cls.lang] = cls
def add_source_suffix(self, suffix: str, filetype: str, override: bool = False) -> None:

View File

@@ -52,11 +52,11 @@ class SearchLanguage:
This class is used to preprocess search word which Sphinx HTML readers
type, before searching index. Default implementation does nothing.
"""
lang: str | None = None
language_name: str | None = None
lang: str = ''
language_name: str = ''
stopwords: set[str] = set()
js_splitter_code: str = ""
js_stemmer_rawcode: str | None = None
js_stemmer_rawcode: str = ''
js_stemmer_code = """
/**
* Dummy stemmer for languages without stemming rules.