Skip to content

Commit c1b2711

Browse files
committed
cleanup
1 parent e352a67 commit c1b2711

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

.ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ exclude = [
518518
"sphinx/ext/autodoc/directive.py",
519519
"sphinx/ext/autodoc/importer.py",
520520
"sphinx/ext/autodoc/type_comment.py",
521-
"sphinx/ext/autodoc/mock.py",
522521
"sphinx/ext/autosummary/__init__.py",
523522
"sphinx/ext/autosummary/generate.py",
524523
"sphinx/pycode/ast.py",

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ module = [
258258
"sphinx.ext.autodoc",
259259
"sphinx.ext.autodoc.directive",
260260
"sphinx.ext.autodoc.importer",
261-
"sphinx.ext.autodoc.mock",
262-
"sphinx.ext.autodoc.mock",
263261
"sphinx.ext.autosummary.generate",
264262
"sphinx.ext.doctest",
265263
"sphinx.ext.graphviz",

sphinx/ext/autodoc/mock.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
from importlib.abc import Loader, MetaPathFinder
99
from importlib.machinery import ModuleSpec
1010
from types import MethodType, ModuleType
11-
from typing import TYPE_CHECKING, Any
11+
from typing import TYPE_CHECKING
1212

1313
from sphinx.util import logging
1414
from sphinx.util.inspect import isboundmethod, safe_getattr
1515

1616
if TYPE_CHECKING:
1717
from collections.abc import Iterator, Sequence
18+
from typing import Any
1819

1920
logger = logging.getLogger(__name__)
2021

@@ -32,8 +33,12 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
3233
superclass = args[1][-1].__class__
3334
if superclass is cls:
3435
# subclassing MockObject
35-
return _make_subclass(args[0], superclass.__display_name__,
36-
superclass=superclass, attributes=args[2])
36+
return _make_subclass(
37+
args[0],
38+
superclass.__display_name__,
39+
superclass=superclass,
40+
attributes=args[2],
41+
)
3742

3843
return super().__new__(cls)
3944

@@ -46,10 +51,10 @@ def __len__(self) -> int:
4651
def __contains__(self, key: str) -> bool:
4752
return False
4853

49-
def __iter__(self) -> Iterator:
54+
def __iter__(self) -> Iterator[Any]:
5055
return iter([])
5156

52-
def __mro_entries__(self, bases: tuple) -> tuple:
57+
def __mro_entries__(self, bases: tuple[Any, ...]) -> tuple[type[Any], ...]:
5358
return (self.__class__,)
5459

5560
def __getitem__(self, key: Any) -> _MockObject:
@@ -67,12 +72,19 @@ def __repr__(self) -> str:
6772
return self.__display_name__
6873

6974

70-
def _make_subclass(name: str, module: str, superclass: Any = _MockObject,
71-
attributes: Any = None, decorator_args: tuple = ()) -> Any:
72-
attrs = {'__module__': module,
73-
'__display_name__': module + '.' + name,
74-
'__name__': name,
75-
'__sphinx_decorator_args__': decorator_args}
75+
def _make_subclass(
76+
name: str,
77+
module: str,
78+
superclass: Any = _MockObject,
79+
attributes: Any = None,
80+
decorator_args: tuple[Any, ...] = (),
81+
) -> Any:
82+
attrs = {
83+
'__module__': module,
84+
'__display_name__': module + '.' + name,
85+
'__name__': name,
86+
'__sphinx_decorator_args__': decorator_args,
87+
}
7688
attrs.update(attributes or {})
7789

7890
return type(name, (superclass,), attrs)
@@ -121,8 +133,12 @@ def __init__(self, modnames: list[str]) -> None:
121133
self.loader = MockLoader(self)
122134
self.mocked_modules: list[str] = []
123135

124-
def find_spec(self, fullname: str, path: Sequence[bytes | str] | None,
125-
target: ModuleType | None = None) -> ModuleSpec | None:
136+
def find_spec(
137+
self,
138+
fullname: str,
139+
path: Sequence[bytes | str] | None,
140+
target: ModuleType | None = None,
141+
) -> ModuleSpec | None:
126142
for modname in self.modnames:
127143
# check if fullname is (or is a descendant of) one of our targets
128144
if modname == fullname or fullname.startswith(modname + '.'):

0 commit comments

Comments
 (0)