Skip to content

Commit

Permalink
[lint] shrink mypy whitelist (#11898)
Browse files Browse the repository at this point in the history
Co-authored-by: Bénédikt Tran <[email protected]>
  • Loading branch information
danieleades and picnixz committed Feb 26, 2024
1 parent 8aa5edd commit adde256
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 24 deletions.
4 changes: 0 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ module = [
"sphinx.highlighting",
"sphinx.jinja2glue",
"sphinx.registry",
"sphinx.roles",
"sphinx.search",
"sphinx.testing.fixtures",
"sphinx.testing.path",
Expand All @@ -203,12 +202,9 @@ module = [
"sphinx.util.display",
"sphinx.util.docfields",
"sphinx.util.docutils",
"sphinx.util.fileutil",
"sphinx.util.i18n",
"sphinx.util.inspect",
"sphinx.util.inventory",
"sphinx.util.logging",
"sphinx.util.nodes",
"sphinx.util.parallel",
"sphinx.util.template",
]
Expand Down
2 changes: 1 addition & 1 deletion sphinx/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def run(self) -> tuple[list[Node], list[system_message]]:
# TODO: Change to use `SphinxRole` once SphinxRole is fixed to support options.
def code_role(name: str, rawtext: str, text: str, lineno: int,
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]]:
if options is None:
options = {}
Expand Down
6 changes: 3 additions & 3 deletions sphinx/util/fileutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import posixpath
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING, Any, Callable

from docutils.utils import relative_path

Expand All @@ -16,7 +16,7 @@


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:
"""Copy an asset file to destination.
Expand Down Expand Up @@ -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],
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:
"""Copy asset files to destination recursively.
Expand Down
25 changes: 16 additions & 9 deletions sphinx/util/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def unwrap(obj: Any) -> Any:
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
functions, and other decorators).
Expand Down Expand Up @@ -352,7 +352,7 @@ def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
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.
Maintains a set of 'seen' object IDs to detect and avoid infinite recursion.
Expand Down Expand Up @@ -546,8 +546,9 @@ def _should_unwrap(subject: Callable) -> bool:
return False


def signature(subject: Callable, bound_method: bool = False, type_aliases: dict | None = None,
) -> inspect.Signature:
def signature(
subject: Callable, bound_method: bool = False, type_aliases: dict[str, str] | None = None,
) -> inspect.Signature:
"""Return a Signature object for the given *subject*.
:param bound_method: Specify *subject* is a bound method or not
Expand Down Expand Up @@ -604,15 +605,19 @@ def signature(subject: Callable, bound_method: bool = False, type_aliases: dict
__validate_parameters__=False)


def evaluate_signature(sig: inspect.Signature, globalns: dict | None = None,
localns: dict | None = None,
def evaluate_signature(sig: inspect.Signature, globalns: dict[str, Any] | None = None,
localns: dict[str, Any] | None = None,
) -> inspect.Signature:
"""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."""
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."""
try:
if isinstance(annotation, str):
Expand Down Expand Up @@ -799,7 +804,9 @@ def getdoc(
* inherited docstring
* 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)
if isinstance(doc, str):
return doc
Expand Down
19 changes: 15 additions & 4 deletions sphinx/util/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InventoryFileReader:
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.buffer = b''
self.eof = False
Expand Down Expand Up @@ -77,7 +77,12 @@ def read_compressed_lines(self) -> Iterator[str]:

class InventoryFile:
@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)
line = reader.readline().rstrip()
if line == '# Sphinx inventory version 1':
Expand All @@ -89,7 +94,10 @@ def load(cls: type[InventoryFile], stream: IO, uri: str, joinfunc: Callable) ->

@classmethod
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:
invdata: Inventory = {}
projname = stream.readline().rstrip()[11:]
Expand All @@ -109,7 +117,10 @@ def load_v1(

@classmethod
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:
invdata: Inventory = {}
projname = stream.readline().rstrip()[11:]
Expand Down
11 changes: 8 additions & 3 deletions sphinx/util/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,14 @@ def process_index_entry(entry: str, targetid: str,
return indexentries


def inline_all_toctrees(builder: Builder, docnameset: set[str], docname: str,
tree: nodes.document, colorfunc: Callable, traversed: list[str],
) -> nodes.document:
def inline_all_toctrees(
builder: Builder,
docnameset: set[str],
docname: str,
tree: nodes.document,
colorfunc: Callable[[str], str],
traversed: list[str],
) -> nodes.document:
"""Inline all toctrees in the *tree*.
Record all docnames in *docnameset*, and output docnames with *colorfunc*.
Expand Down

0 comments on commit adde256

Please sign in to comment.