1010
1111import re
1212import unicodedata
13- from typing import TYPE_CHECKING , Any , Callable , Iterable , List , Set , Tuple , Type , Union , cast
13+ from typing import (TYPE_CHECKING , Any , Callable , Iterable , List , Optional , Set , Tuple , Type ,
14+ Union , cast )
1415
1516from docutils import nodes
1617from docutils .nodes import Element , Node
@@ -170,7 +171,7 @@ def apply_source_workaround(node: Element) -> None:
170171 ))):
171172 logger .debug ('[i18n] PATCH: %r to have source and line: %s' ,
172173 get_full_module_name (node ), repr_domxml (node ))
173- node .source = get_node_source (node )
174+ node .source = get_node_source (node ) or ''
174175 node .line = 0 # need fix docutils to get `node.line`
175176 return
176177
@@ -266,7 +267,7 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]:
266267 if node .get ('translatable' ):
267268 msg = '.. image:: %s' % node ['uri' ]
268269 else :
269- msg = None
270+ msg = ''
270271 elif isinstance (node , META_TYPE_NODES ):
271272 msg = node .rawcontent
272273 elif isinstance (node , nodes .pending ) and is_pending_meta (node ):
@@ -279,14 +280,14 @@ def extract_messages(doctree: Element) -> Iterable[Tuple[Element, str]]:
279280 yield node , msg
280281
281282
282- def get_node_source (node : Element ) -> str :
283+ def get_node_source (node : Element ) -> Optional [ str ] :
283284 for pnode in traverse_parent (node ):
284285 if pnode .source :
285286 return pnode .source
286287 return None
287288
288289
289- def get_node_line (node : Element ) -> int :
290+ def get_node_line (node : Element ) -> Optional [ int ] :
290291 for pnode in traverse_parent (node ):
291292 if pnode .line :
292293 return pnode .line
@@ -300,7 +301,7 @@ def traverse_parent(node: Element, cls: Any = None) -> Iterable[Element]:
300301 node = node .parent
301302
302303
303- def get_prev_node (node : Node ) -> Node :
304+ def get_prev_node (node : Node ) -> Optional [ Node ] :
304305 pos = node .parent .index (node )
305306 if pos > 0 :
306307 return node .parent [pos - 1 ]
@@ -360,10 +361,11 @@ def split_explicit_title(text: str) -> Tuple[bool, str, str]:
360361]
361362
362363
363- def process_index_entry (entry : str , targetid : str ) -> List [Tuple [str , str , str , str , str ]]:
364+ def process_index_entry (entry : str , targetid : str
365+ ) -> List [Tuple [str , str , str , str , Optional [str ]]]:
364366 from sphinx .domains .python import pairindextypes
365367
366- indexentries : List [Tuple [str , str , str , str , str ]] = []
368+ indexentries : List [Tuple [str , str , str , str , Optional [ str ] ]] = []
367369 entry = entry .strip ()
368370 oentry = entry
369371 main = ''
@@ -531,7 +533,8 @@ def make_id(env: "BuildEnvironment", document: nodes.document,
531533 return node_id
532534
533535
534- def find_pending_xref_condition (node : addnodes .pending_xref , condition : str ) -> Element :
536+ def find_pending_xref_condition (node : addnodes .pending_xref , condition : str
537+ ) -> Optional [Element ]:
535538 """Pick matched pending_xref_condition node up from the pending_xref."""
536539 for subnode in node :
537540 if (isinstance (subnode , addnodes .pending_xref_condition ) and
0 commit comments