diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index dbbc20956..91e975a96 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -31,7 +31,7 @@ if False: from sphinx.application import Sphinx # NOQA from sphinx.builders import Builder # NOQA from sphinx.environment import BuildEnvironment # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import TextlikeNode, unicode # NOQA logger = logging.getLogger(__name__) @@ -120,7 +120,7 @@ class PyXrefMixin: rolename, # type: unicode domain, # type: unicode target, # type: unicode - innernode=nodes.emphasis, # type: Type[nodes.TextElement] + innernode=nodes.emphasis, # type: Type[TextlikeNode] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment ): @@ -143,7 +143,7 @@ class PyXrefMixin: rolename, # type: unicode domain, # type: unicode target, # type: unicode - innernode=nodes.emphasis, # type: Type[nodes.TextElement] + innernode=nodes.emphasis, # type: Type[TextlikeNode] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment ): @@ -171,7 +171,7 @@ class PyXrefMixin: class PyField(PyXrefMixin, Field): def make_xref(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None, env=None): - # type: (unicode, unicode, unicode, Type[nodes.TextElement], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA + # type: (unicode, unicode, unicode, Type[TextlikeNode], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA if rolename == 'class' and target == 'None': # None is not a type, so use obj role instead. rolename = 'obj' @@ -187,7 +187,7 @@ class PyGroupedField(PyXrefMixin, GroupedField): class PyTypedField(PyXrefMixin, TypedField): def make_xref(self, rolename, domain, target, innernode=nodes.emphasis, contnode=None, env=None): - # type: (unicode, unicode, unicode, Type[nodes.TextElement], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA + # type: (unicode, unicode, unicode, Type[TextlikeNode], nodes.Node, BuildEnvironment) -> nodes.Node # NOQA if rolename == 'class' and target == 'None': # None is not a type, so use obj role instead. rolename = 'obj' diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 22080f95b..71126dded 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -22,7 +22,7 @@ if False: from typing import Any, Dict, Tuple, Type # NOQA from sphinx.domains import Domain # NOQA from sphinx.environment import BuildEnvironment # NOQA - from sphinx.util.typing import unicode # NOQA + from sphinx.util.typing import TextlikeNode, unicode # NOQA def _is_single_paragraph(node): @@ -69,7 +69,7 @@ class Field: rolename, # type: unicode domain, # type: unicode target, # type: unicode - innernode=addnodes.literal_emphasis, # type: Type[nodes.TextElement] + innernode=addnodes.literal_emphasis, # type: Type[TextlikeNode] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment ): @@ -87,7 +87,7 @@ class Field: rolename, # type: unicode domain, # type: unicode target, # type: unicode - innernode=addnodes.literal_emphasis, # type: Type[nodes.TextElement] + innernode=addnodes.literal_emphasis, # type: Type[TextlikeNode] contnode=None, # type: nodes.Node env=None, # type: BuildEnvironment ): diff --git a/sphinx/util/typing.py b/sphinx/util/typing.py index 973d8b85f..72ef77742 100644 --- a/sphinx/util/typing.py +++ b/sphinx/util/typing.py @@ -9,7 +9,7 @@ :license: BSD, see LICENSE for details. """ -from typing import Any, Callable, Dict, List, Tuple +from typing import Any, Callable, Dict, List, Tuple, Union from docutils import nodes from docutils.parsers.rst.states import Inliner @@ -26,6 +26,9 @@ else: # An entry of Directive.option_spec DirectiveOption = Callable[[str], Any] +# Text like nodes which are initialized with text and rawsource +TextlikeNode = Union[nodes.Text, nodes.TextElement] + # common role functions RoleFunction = Callable[[text_type, text_type, text_type, int, Inliner, Dict, List[text_type]], Tuple[List[nodes.Node], List[nodes.system_message]]]