|
24 | 24 |
|
25 | 25 | if TYPE_CHECKING: |
26 | 26 | from collections.abc import Mapping |
27 | | - from typing import Final, Literal |
| 27 | + from typing import Final, Literal, Protocol |
28 | 28 |
|
29 | 29 | from docutils.parsers.rst.states import RSTState as _RSTStateGeneric |
30 | 30 | from typing_extensions import TypeAlias, TypeIs |
@@ -95,10 +95,25 @@ def is_invalid_builtin_class(obj: Any) -> bool: |
95 | 95 | PathMatcher = Callable[[str], bool] |
96 | 96 |
|
97 | 97 | # common role functions |
98 | | -RoleFunction = Callable[ |
99 | | - [str, str, str, int, Inliner, dict[str, Any], Sequence[str]], |
100 | | - tuple[list[nodes.Node], list[nodes.system_message]], |
101 | | -] |
| 98 | +if TYPE_CHECKING: |
| 99 | + class RoleFunction(Protocol): |
| 100 | + def __call__( |
| 101 | + self, |
| 102 | + name: str, |
| 103 | + rawtext: str, |
| 104 | + text: str, |
| 105 | + lineno: int, |
| 106 | + inliner: Inliner, |
| 107 | + /, |
| 108 | + options: dict[str, Any] | None = None, |
| 109 | + content: Sequence[str] = (), |
| 110 | + ) -> tuple[list[nodes.Node], list[nodes.system_message]]: |
| 111 | + ... |
| 112 | +else: |
| 113 | + RoleFunction = Callable[ |
| 114 | + [str, str, str, int, Inliner, dict[str, Any], Sequence[str]], |
| 115 | + tuple[list[nodes.Node], list[nodes.system_message]], |
| 116 | + ] |
102 | 117 |
|
103 | 118 | # A option spec for directive |
104 | 119 | OptionSpec = dict[str, Callable[[str], Any]] |
|
0 commit comments