diff options
Diffstat (limited to 'sphinx/ext/extlinks.py')
-rw-r--r-- | sphinx/ext/extlinks.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py index 7ad721b8f..39a989f23 100644 --- a/sphinx/ext/extlinks.py +++ b/sphinx/ext/extlinks.py @@ -23,23 +23,22 @@ :license: BSD, see LICENSE for details. """ +from typing import Any, Dict, List, Tuple + from docutils import nodes, utils +from docutils.nodes import Node, system_message +from docutils.parsers.rst.states import Inliner import sphinx +from sphinx.application import Sphinx from sphinx.util.nodes import split_explicit_title - -if False: - # For type annotation - from typing import Any, Dict, List, Tuple # NOQA - from docutils.parsers.rst.states import Inliner # NOQA - from sphinx.application import Sphinx # NOQA - from sphinx.util.typing import RoleFunction # NOQA +from sphinx.util.typing import RoleFunction -def make_link_role(base_url, prefix): - # type: (str, str) -> RoleFunction - def role(typ, rawtext, text, lineno, inliner, options={}, content=[]): - # type: (str, str, str, int, Inliner, Dict, List[str]) -> Tuple[List[nodes.Node], List[nodes.system_message]] # NOQA +def make_link_role(base_url: str, prefix: str) -> RoleFunction: + def role(typ: str, rawtext: str, text: str, lineno: int, + inliner: Inliner, options: Dict = {}, content: List[str] = [] + ) -> Tuple[List[Node], List[system_message]]: text = utils.unescape(text) has_explicit_title, title, part = split_explicit_title(text) try: @@ -60,14 +59,12 @@ def make_link_role(base_url, prefix): return role -def setup_link_roles(app): - # type: (Sphinx) -> None +def setup_link_roles(app: Sphinx) -> None: for name, (base_url, prefix) in app.config.extlinks.items(): app.add_role(name, make_link_role(base_url, prefix)) -def setup(app): - # type: (Sphinx) -> Dict[str, Any] +def setup(app: Sphinx) -> Dict[str, Any]: app.add_config_value('extlinks', {}, 'env') app.connect('builder-inited', setup_link_roles) return {'version': sphinx.__display_version__, 'parallel_read_safe': True} |