13
13
# limitations under the License.
14
14
# ==============================================================================
15
15
"""A `traverse` visitor for processing documentation."""
16
+ from __future__ import annotations
16
17
17
18
import collections
18
19
import dataclasses
@@ -73,8 +74,8 @@ class PathTreeNode(object):
73
74
"""
74
75
path : ApiPath
75
76
py_object : Any
76
- parent : Optional [' PathTreeNode' ] = None
77
- children : Dict [str , ' PathTreeNode' ] = dataclasses .field (default_factory = dict )
77
+ parent : Optional [PathTreeNode ] = None
78
+ children : Dict [str , PathTreeNode ] = dataclasses .field (default_factory = dict )
78
79
79
80
def __hash__ (self ):
80
81
return id (self )
@@ -478,6 +479,7 @@ def output_type(self) -> OutputType:
478
479
return self .OutputType .PAGE
479
480
elif obj_type in (obj_type_lib .ObjType .CALLABLE ,
480
481
obj_type_lib .ObjType .TYPE_ALIAS ):
482
+ assert self .parent is not None
481
483
parent_type = obj_type_lib .ObjType .get (self .parent .py_object )
482
484
if parent_type is obj_type_lib .ObjType .CLASS :
483
485
return self .OutputType .FRAGMENT
@@ -589,9 +591,8 @@ def _get_physical_path(self, py_object):
589
591
590
592
return physical_path
591
593
592
-
593
594
@classmethod
594
- def from_path_tree (cls , path_tree : PathTree , score_name_fn ) -> ' ApiTree' :
595
+ def from_path_tree (cls , path_tree : PathTree , score_name_fn ) -> ApiTree :
595
596
"""Create an ApiTree from an PathTree.
596
597
597
598
Args:
@@ -615,16 +616,19 @@ def from_path_tree(cls, path_tree: PathTree, score_name_fn) -> 'ApiTree':
615
616
if not duplicate_nodes :
616
617
# Singleton objects will return `[]`. So look up the parent object's
617
618
# duplicate nodes and collect their children.
619
+ assert current_node .parent is not None
618
620
parent_nodes = path_tree .nodes_for_obj (current_node .parent .py_object )
619
621
duplicate_nodes = [
620
622
parent_node .children [current_node .short_name ]
621
623
for parent_node in parent_nodes
622
624
]
623
625
624
- parents = [node .parent for node in duplicate_nodes ]
626
+ parents = [
627
+ node .parent for node in duplicate_nodes if node .parent is not None
628
+ ]
625
629
626
630
# Choose the priority name with a lexical sort on the tuples returned by
627
- # by _score_name.
631
+ # _score_name.
628
632
if not all (parent .path in self for parent in parents ):
629
633
# rewind
630
634
active_nodes .appendleft (current_node )
0 commit comments