diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-03-28 07:31:52 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-05-03 22:41:19 +0900 |
commit | 930bf6c327b31aec6112359695f35a2c77fbae21 (patch) | |
tree | 77ec4b549ad46ea2c52b9ba40a0f011451378305 /sphinx/util/nodes.py | |
parent | f31af4b8158e6142d918366aa0026e40575af914 (diff) | |
download | sphinx-git-930bf6c327b31aec6112359695f35a2c77fbae21.tar.gz |
refactor: Add Optional to type annotations
Diffstat (limited to 'sphinx/util/nodes.py')
-rw-r--r-- | sphinx/util/nodes.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 44eb5d303..36db149b9 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -10,7 +10,8 @@ import re import unicodedata -from typing import TYPE_CHECKING, Any, Callable, Iterable, List, Set, Tuple, Type, Union, cast +from typing import (TYPE_CHECKING, Any, Callable, Iterable, List, Optional, Set, Tuple, Type, + Union, cast) from docutils import nodes from docutils.nodes import Element, Node @@ -170,7 +171,7 @@ def apply_source_workaround(node: Element) -> None: ))): logger.debug('[i18n] PATCH: %r to have source and line: %s', get_full_module_name(node), repr_domxml(node)) - node.source = get_node_source(node) + node.source = get_node_source(node) or '' node.line = 0 # need fix docutils to get `node.line` return @@ -266,7 +267,7 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]: if node.get('translatable'): msg = '.. image:: %s' % node['uri'] else: - msg = None + msg = '' elif isinstance(node, META_TYPE_NODES): msg = node.rawcontent elif isinstance(node, nodes.pending) and is_pending_meta(node): @@ -279,14 +280,14 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]: yield node, msg -def get_node_source(node: Element) -> str: +def get_node_source(node: Element) -> Optional[str]: for pnode in traverse_parent(node): if pnode.source: return pnode.source return None -def get_node_line(node: Element) -> int: +def get_node_line(node: Element) -> Optional[int]: for pnode in traverse_parent(node): if pnode.line: return pnode.line @@ -300,7 +301,7 @@ def traverse_parent(node: Element, cls: Any = None) -> Iterable[Element]: node = node.parent -def get_prev_node(node: Node) -> Node: +def get_prev_node(node: Node) -> Optional[Node]: pos = node.parent.index(node) if pos > 0: return node.parent[pos - 1] @@ -360,10 +361,11 @@ indextypes = [ ] -def process_index_entry(entry: str, targetid: str) -> List[Tuple[str, str, str, str, str]]: +def process_index_entry(entry: str, targetid: str + ) -> List[Tuple[str, str, str, str, Optional[str]]]: from sphinx.domains.python import pairindextypes - indexentries: List[Tuple[str, str, str, str, str]] = [] + indexentries: List[Tuple[str, str, str, str, Optional[str]]] = [] entry = entry.strip() oentry = entry main = '' @@ -531,7 +533,8 @@ def make_id(env: "BuildEnvironment", document: nodes.document, return node_id -def find_pending_xref_condition(node: addnodes.pending_xref, condition: str) -> Element: +def find_pending_xref_condition(node: addnodes.pending_xref, condition: str + ) -> Optional[Element]: """Pick matched pending_xref_condition node up from the pending_xref.""" for subnode in node: if (isinstance(subnode, addnodes.pending_xref_condition) and |