mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use a protocol for `RoleFunction
` (#12513)
This commit is contained in:
parent
e63e2f3ccb
commit
59e95531b9
@ -385,7 +385,7 @@ class InheritanceDiagram(SphinxDirective):
|
||||
# references to real URLs later. These nodes will eventually be
|
||||
# removed from the doctree after we're done with them.
|
||||
for name in graph.get_all_class_names():
|
||||
refnodes, x = class_role( # type: ignore[call-arg,misc]
|
||||
refnodes, x = class_role( # type: ignore[misc]
|
||||
'class', ':class:`%s`' % name, name, 0, self.state.inliner)
|
||||
node.extend(refnodes)
|
||||
# Store the graph object so we can use it to generate the
|
||||
|
@ -24,7 +24,7 @@ from docutils.parsers.rst.states import Inliner
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from collections.abc import Mapping
|
||||
from typing import Final, Literal
|
||||
from typing import Final, Literal, Protocol
|
||||
|
||||
from docutils.parsers.rst.states import RSTState as _RSTStateGeneric
|
||||
from typing_extensions import TypeAlias, TypeIs
|
||||
@ -95,10 +95,25 @@ NoneType = type(None)
|
||||
PathMatcher = Callable[[str], bool]
|
||||
|
||||
# common role functions
|
||||
RoleFunction = Callable[
|
||||
[str, str, str, int, Inliner, dict[str, Any], Sequence[str]],
|
||||
tuple[list[nodes.Node], list[nodes.system_message]],
|
||||
]
|
||||
if TYPE_CHECKING:
|
||||
class RoleFunction(Protocol):
|
||||
def __call__(
|
||||
self,
|
||||
name: str,
|
||||
rawtext: str,
|
||||
text: str,
|
||||
lineno: int,
|
||||
inliner: Inliner,
|
||||
/,
|
||||
options: dict[str, Any] | None = None,
|
||||
content: Sequence[str] = (),
|
||||
) -> tuple[list[nodes.Node], list[nodes.system_message]]:
|
||||
...
|
||||
else:
|
||||
RoleFunction = Callable[
|
||||
[str, str, str, int, Inliner, dict[str, Any], Sequence[str]],
|
||||
tuple[list[nodes.Node], list[nodes.system_message]],
|
||||
]
|
||||
|
||||
# A option spec for directive
|
||||
OptionSpec = dict[str, Callable[[str], Any]]
|
||||
|
Loading…
Reference in New Issue
Block a user