[lint] shrink mypy whitelist (#11898)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
danieleades 2024-02-26 08:45:19 +00:00 committed by GitHub
parent 8aa5edd585
commit adde256893
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 43 additions and 24 deletions

View File

@ -194,7 +194,6 @@ module = [
"sphinx.highlighting", "sphinx.highlighting",
"sphinx.jinja2glue", "sphinx.jinja2glue",
"sphinx.registry", "sphinx.registry",
"sphinx.roles",
"sphinx.search", "sphinx.search",
"sphinx.testing.fixtures", "sphinx.testing.fixtures",
"sphinx.testing.path", "sphinx.testing.path",
@ -203,12 +202,9 @@ module = [
"sphinx.util.display", "sphinx.util.display",
"sphinx.util.docfields", "sphinx.util.docfields",
"sphinx.util.docutils", "sphinx.util.docutils",
"sphinx.util.fileutil",
"sphinx.util.i18n", "sphinx.util.i18n",
"sphinx.util.inspect", "sphinx.util.inspect",
"sphinx.util.inventory",
"sphinx.util.logging", "sphinx.util.logging",
"sphinx.util.nodes",
"sphinx.util.parallel", "sphinx.util.parallel",
"sphinx.util.template", "sphinx.util.template",
] ]

View File

@ -389,7 +389,7 @@ class Manpage(ReferenceRole):
# TODO: Change to use `SphinxRole` once SphinxRole is fixed to support options. # TODO: Change to use `SphinxRole` once SphinxRole is fixed to support options.
def code_role(name: str, rawtext: str, text: str, lineno: int, def code_role(name: str, rawtext: str, text: str, lineno: int,
inliner: docutils.parsers.rst.states.Inliner, inliner: docutils.parsers.rst.states.Inliner,
options: dict | None = None, content: Sequence[str] = (), options: dict[str, Any] | None = None, content: Sequence[str] = (),
) -> tuple[list[Node], list[system_message]]: ) -> tuple[list[Node], list[system_message]]:
if options is None: if options is None:
options = {} options = {}

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import os import os
import posixpath import posixpath
from typing import TYPE_CHECKING, Callable from typing import TYPE_CHECKING, Any, Callable
from docutils.utils import relative_path from docutils.utils import relative_path
@ -16,7 +16,7 @@ if TYPE_CHECKING:
def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLike[str], def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLike[str],
context: dict | None = None, context: dict[str, Any] | None = None,
renderer: BaseRenderer | None = None) -> None: renderer: BaseRenderer | None = None) -> None:
"""Copy an asset file to destination. """Copy an asset file to destination.
@ -53,7 +53,7 @@ def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLi
def copy_asset(source: str | os.PathLike[str], destination: str | os.PathLike[str], def copy_asset(source: str | os.PathLike[str], destination: str | os.PathLike[str],
excluded: PathMatcher = lambda path: False, excluded: PathMatcher = lambda path: False,
context: dict | None = None, renderer: BaseRenderer | None = None, context: dict[str, Any] | None = None, renderer: BaseRenderer | None = None,
onerror: Callable[[str, Exception], None] | None = None) -> None: onerror: Callable[[str, Exception], None] | None = None) -> None:
"""Copy asset files to destination recursively. """Copy asset files to destination recursively.

View File

@ -53,7 +53,7 @@ def unwrap(obj: Any) -> Any:
return obj return obj
def unwrap_all(obj: Any, *, stop: Callable | None = None) -> Any: def unwrap_all(obj: Any, *, stop: Callable[[Any], bool] | None = None) -> Any:
""" """
Get an original object from wrapped object (unwrapping partials, wrapped Get an original object from wrapped object (unwrapping partials, wrapped
functions, and other decorators). functions, and other decorators).
@ -352,7 +352,7 @@ def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
raise AttributeError(name) from exc raise AttributeError(name) from exc
def object_description(obj: Any, *, _seen: frozenset = frozenset()) -> str: def object_description(obj: Any, *, _seen: frozenset[int] = frozenset()) -> str:
"""A repr() implementation that returns text safe to use in reST context. """A repr() implementation that returns text safe to use in reST context.
Maintains a set of 'seen' object IDs to detect and avoid infinite recursion. Maintains a set of 'seen' object IDs to detect and avoid infinite recursion.
@ -546,8 +546,9 @@ def _should_unwrap(subject: Callable) -> bool:
return False return False
def signature(subject: Callable, bound_method: bool = False, type_aliases: dict | None = None, def signature(
) -> inspect.Signature: subject: Callable, bound_method: bool = False, type_aliases: dict[str, str] | None = None,
) -> inspect.Signature:
"""Return a Signature object for the given *subject*. """Return a Signature object for the given *subject*.
:param bound_method: Specify *subject* is a bound method or not :param bound_method: Specify *subject* is a bound method or not
@ -604,15 +605,19 @@ def signature(subject: Callable, bound_method: bool = False, type_aliases: dict
__validate_parameters__=False) __validate_parameters__=False)
def evaluate_signature(sig: inspect.Signature, globalns: dict | None = None, def evaluate_signature(sig: inspect.Signature, globalns: dict[str, Any] | None = None,
localns: dict | None = None, localns: dict[str, Any] | None = None,
) -> inspect.Signature: ) -> inspect.Signature:
"""Evaluate unresolved type annotations in a signature object.""" """Evaluate unresolved type annotations in a signature object."""
def evaluate_forwardref(ref: ForwardRef, globalns: dict, localns: dict) -> Any: def evaluate_forwardref(
ref: ForwardRef, globalns: dict[str, Any] | None, localns: dict[str, Any] | None,
) -> Any:
"""Evaluate a forward reference.""" """Evaluate a forward reference."""
return ref._evaluate(globalns, localns, frozenset()) return ref._evaluate(globalns, localns, frozenset())
def evaluate(annotation: Any, globalns: dict, localns: dict) -> Any: def evaluate(
annotation: Any, globalns: dict[str, Any], localns: dict[str, Any],
) -> Any:
"""Evaluate unresolved type annotation.""" """Evaluate unresolved type annotation."""
try: try:
if isinstance(annotation, str): if isinstance(annotation, str):
@ -799,7 +804,9 @@ def getdoc(
* inherited docstring * inherited docstring
* inherited decorated methods * inherited decorated methods
""" """
def getdoc_internal(obj: Any, attrgetter: Callable = safe_getattr) -> str | None: def getdoc_internal(
obj: Any, attrgetter: Callable[[Any, str, Any], Any] = safe_getattr,
) -> str | None:
doc = attrgetter(obj, '__doc__', None) doc = attrgetter(obj, '__doc__', None)
if isinstance(doc, str): if isinstance(doc, str):
return doc return doc

View File

@ -25,7 +25,7 @@ class InventoryFileReader:
This reader supports mixture of texts and compressed texts. This reader supports mixture of texts and compressed texts.
""" """
def __init__(self, stream: IO) -> None: def __init__(self, stream: IO[bytes]) -> None:
self.stream = stream self.stream = stream
self.buffer = b'' self.buffer = b''
self.eof = False self.eof = False
@ -77,7 +77,12 @@ class InventoryFileReader:
class InventoryFile: class InventoryFile:
@classmethod @classmethod
def load(cls: type[InventoryFile], stream: IO, uri: str, joinfunc: Callable) -> Inventory: def load(
cls: type[InventoryFile],
stream: IO[bytes],
uri: str,
joinfunc: Callable[[str, str], str],
) -> Inventory:
reader = InventoryFileReader(stream) reader = InventoryFileReader(stream)
line = reader.readline().rstrip() line = reader.readline().rstrip()
if line == '# Sphinx inventory version 1': if line == '# Sphinx inventory version 1':
@ -89,7 +94,10 @@ class InventoryFile:
@classmethod @classmethod
def load_v1( def load_v1(
cls: type[InventoryFile], stream: InventoryFileReader, uri: str, join: Callable, cls: type[InventoryFile],
stream: InventoryFileReader,
uri: str,
join: Callable[[str, str], str],
) -> Inventory: ) -> Inventory:
invdata: Inventory = {} invdata: Inventory = {}
projname = stream.readline().rstrip()[11:] projname = stream.readline().rstrip()[11:]
@ -109,7 +117,10 @@ class InventoryFile:
@classmethod @classmethod
def load_v2( def load_v2(
cls: type[InventoryFile], stream: InventoryFileReader, uri: str, join: Callable, cls: type[InventoryFile],
stream: InventoryFileReader,
uri: str,
join: Callable[[str, str], str],
) -> Inventory: ) -> Inventory:
invdata: Inventory = {} invdata: Inventory = {}
projname = stream.readline().rstrip()[11:] projname = stream.readline().rstrip()[11:]

View File

@ -402,9 +402,14 @@ def process_index_entry(entry: str, targetid: str,
return indexentries return indexentries
def inline_all_toctrees(builder: Builder, docnameset: set[str], docname: str, def inline_all_toctrees(
tree: nodes.document, colorfunc: Callable, traversed: list[str], builder: Builder,
) -> nodes.document: docnameset: set[str],
docname: str,
tree: nodes.document,
colorfunc: Callable[[str], str],
traversed: list[str],
) -> nodes.document:
"""Inline all toctrees in the *tree*. """Inline all toctrees in the *tree*.
Record all docnames in *docnameset*, and output docnames with *colorfunc*. Record all docnames in *docnameset*, and output docnames with *colorfunc*.