Skip to content

Commit 8524dc0

Browse files
authored
Merge branch 'master' into master
2 parents 224efa3 + d6f38ad commit 8524dc0

File tree

7 files changed

+46
-26
lines changed

7 files changed

+46
-26
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ jobs:
6262
- name: Install dependencies
6363
run: |
6464
python -m pip install --upgrade pip
65-
python -m pip install --upgrade "mypy==1.8.0" docutils-stubs types-requests
65+
python -m pip install ".[lint,test]"
6666
- name: Type check with mypy
67-
run: mypy sphinx/
67+
run: mypy
6868

6969
docs-lint:
7070
runs-on: ubuntu-latest

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ exclude = [
130130
]
131131

132132
[tool.mypy]
133+
files = ["sphinx"]
133134
check_untyped_defs = true
134135
disallow_incomplete_defs = true
135136
follow_imports = "skip"
@@ -194,7 +195,6 @@ module = [
194195
"sphinx.highlighting",
195196
"sphinx.jinja2glue",
196197
"sphinx.registry",
197-
"sphinx.roles",
198198
"sphinx.search",
199199
"sphinx.testing.fixtures",
200200
"sphinx.testing.path",
@@ -203,12 +203,9 @@ module = [
203203
"sphinx.util.display",
204204
"sphinx.util.docfields",
205205
"sphinx.util.docutils",
206-
"sphinx.util.fileutil",
207206
"sphinx.util.i18n",
208207
"sphinx.util.inspect",
209-
"sphinx.util.inventory",
210208
"sphinx.util.logging",
211-
"sphinx.util.nodes",
212209
"sphinx.util.parallel",
213210
"sphinx.util.template",
214211
]

sphinx/roles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def run(self) -> tuple[list[Node], list[system_message]]:
389389
# TODO: Change to use `SphinxRole` once SphinxRole is fixed to support options.
390390
def code_role(name: str, rawtext: str, text: str, lineno: int,
391391
inliner: docutils.parsers.rst.states.Inliner,
392-
options: dict | None = None, content: Sequence[str] = (),
392+
options: dict[str, Any] | None = None, content: Sequence[str] = (),
393393
) -> tuple[list[Node], list[system_message]]:
394394
if options is None:
395395
options = {}

sphinx/util/fileutil.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import os
66
import posixpath
7-
from typing import TYPE_CHECKING, Callable
7+
from typing import TYPE_CHECKING, Any, Callable
88

99
from docutils.utils import relative_path
1010

@@ -16,7 +16,7 @@
1616

1717

1818
def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLike[str],
19-
context: dict | None = None,
19+
context: dict[str, Any] | None = None,
2020
renderer: BaseRenderer | None = None) -> None:
2121
"""Copy an asset file to destination.
2222
@@ -53,7 +53,7 @@ def copy_asset_file(source: str | os.PathLike[str], destination: str | os.PathLi
5353

5454
def copy_asset(source: str | os.PathLike[str], destination: str | os.PathLike[str],
5555
excluded: PathMatcher = lambda path: False,
56-
context: dict | None = None, renderer: BaseRenderer | None = None,
56+
context: dict[str, Any] | None = None, renderer: BaseRenderer | None = None,
5757
onerror: Callable[[str, Exception], None] | None = None) -> None:
5858
"""Copy asset files to destination recursively.
5959

sphinx/util/inspect.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def unwrap(obj: Any) -> Any:
5353
return obj
5454

5555

56-
def unwrap_all(obj: Any, *, stop: Callable | None = None) -> Any:
56+
def unwrap_all(obj: Any, *, stop: Callable[[Any], bool] | None = None) -> Any:
5757
"""
5858
Get an original object from wrapped object (unwrapping partials, wrapped
5959
functions, and other decorators).
@@ -352,7 +352,7 @@ def safe_getattr(obj: Any, name: str, *defargs: Any) -> Any:
352352
raise AttributeError(name) from exc
353353

354354

355-
def object_description(obj: Any, *, _seen: frozenset = frozenset()) -> str:
355+
def object_description(obj: Any, *, _seen: frozenset[int] = frozenset()) -> str:
356356
"""A repr() implementation that returns text safe to use in reST context.
357357
358358
Maintains a set of 'seen' object IDs to detect and avoid infinite recursion.
@@ -546,8 +546,9 @@ def _should_unwrap(subject: Callable) -> bool:
546546
return False
547547

548548

549-
def signature(subject: Callable, bound_method: bool = False, type_aliases: dict | None = None,
550-
) -> inspect.Signature:
549+
def signature(
550+
subject: Callable, bound_method: bool = False, type_aliases: dict[str, str] | None = None,
551+
) -> inspect.Signature:
551552
"""Return a Signature object for the given *subject*.
552553
553554
: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
604605
__validate_parameters__=False)
605606

606607

607-
def evaluate_signature(sig: inspect.Signature, globalns: dict | None = None,
608-
localns: dict | None = None,
608+
def evaluate_signature(sig: inspect.Signature, globalns: dict[str, Any] | None = None,
609+
localns: dict[str, Any] | None = None,
609610
) -> inspect.Signature:
610611
"""Evaluate unresolved type annotations in a signature object."""
611-
def evaluate_forwardref(ref: ForwardRef, globalns: dict, localns: dict) -> Any:
612+
def evaluate_forwardref(
613+
ref: ForwardRef, globalns: dict[str, Any] | None, localns: dict[str, Any] | None,
614+
) -> Any:
612615
"""Evaluate a forward reference."""
613616
return ref._evaluate(globalns, localns, frozenset())
614617

615-
def evaluate(annotation: Any, globalns: dict, localns: dict) -> Any:
618+
def evaluate(
619+
annotation: Any, globalns: dict[str, Any], localns: dict[str, Any],
620+
) -> Any:
616621
"""Evaluate unresolved type annotation."""
617622
try:
618623
if isinstance(annotation, str):
@@ -799,7 +804,9 @@ def getdoc(
799804
* inherited docstring
800805
* inherited decorated methods
801806
"""
802-
def getdoc_internal(obj: Any, attrgetter: Callable = safe_getattr) -> str | None:
807+
def getdoc_internal(
808+
obj: Any, attrgetter: Callable[[Any, str, Any], Any] = safe_getattr,
809+
) -> str | None:
803810
doc = attrgetter(obj, '__doc__', None)
804811
if isinstance(doc, str):
805812
return doc

sphinx/util/inventory.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class InventoryFileReader:
2525
This reader supports mixture of texts and compressed texts.
2626
"""
2727

28-
def __init__(self, stream: IO) -> None:
28+
def __init__(self, stream: IO[bytes]) -> None:
2929
self.stream = stream
3030
self.buffer = b''
3131
self.eof = False
@@ -77,7 +77,12 @@ def read_compressed_lines(self) -> Iterator[str]:
7777

7878
class InventoryFile:
7979
@classmethod
80-
def load(cls: type[InventoryFile], stream: IO, uri: str, joinfunc: Callable) -> Inventory:
80+
def load(
81+
cls: type[InventoryFile],
82+
stream: IO[bytes],
83+
uri: str,
84+
joinfunc: Callable[[str, str], str],
85+
) -> Inventory:
8186
reader = InventoryFileReader(stream)
8287
line = reader.readline().rstrip()
8388
if line == '# Sphinx inventory version 1':
@@ -89,7 +94,10 @@ def load(cls: type[InventoryFile], stream: IO, uri: str, joinfunc: Callable) ->
8994

9095
@classmethod
9196
def load_v1(
92-
cls: type[InventoryFile], stream: InventoryFileReader, uri: str, join: Callable,
97+
cls: type[InventoryFile],
98+
stream: InventoryFileReader,
99+
uri: str,
100+
join: Callable[[str, str], str],
93101
) -> Inventory:
94102
invdata: Inventory = {}
95103
projname = stream.readline().rstrip()[11:]
@@ -109,7 +117,10 @@ def load_v1(
109117

110118
@classmethod
111119
def load_v2(
112-
cls: type[InventoryFile], stream: InventoryFileReader, uri: str, join: Callable,
120+
cls: type[InventoryFile],
121+
stream: InventoryFileReader,
122+
uri: str,
123+
join: Callable[[str, str], str],
113124
) -> Inventory:
114125
invdata: Inventory = {}
115126
projname = stream.readline().rstrip()[11:]

sphinx/util/nodes.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,14 @@ def process_index_entry(entry: str, targetid: str,
402402
return indexentries
403403

404404

405-
def inline_all_toctrees(builder: Builder, docnameset: set[str], docname: str,
406-
tree: nodes.document, colorfunc: Callable, traversed: list[str],
407-
) -> nodes.document:
405+
def inline_all_toctrees(
406+
builder: Builder,
407+
docnameset: set[str],
408+
docname: str,
409+
tree: nodes.document,
410+
colorfunc: Callable[[str], str],
411+
traversed: list[str],
412+
) -> nodes.document:
408413
"""Inline all toctrees in the *tree*.
409414
410415
Record all docnames in *docnameset*, and output docnames with *colorfunc*.

0 commit comments

Comments
 (0)