Skip to content

Commit 4c9b075

Browse files
markmcdcopybara-github
authored andcommitted
Fixing pytype annotations.
PiperOrigin-RevId: 518151342
1 parent 393d7b6 commit 4c9b075

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tools/tensorflow_docs/api_generator/doc_generator_visitor.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515
"""A `traverse` visitor for processing documentation."""
16+
from __future__ import annotations
1617

1718
import collections
1819
import dataclasses
@@ -73,8 +74,8 @@ class PathTreeNode(object):
7374
"""
7475
path: ApiPath
7576
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)
7879

7980
def __hash__(self):
8081
return id(self)
@@ -478,6 +479,7 @@ def output_type(self) -> OutputType:
478479
return self.OutputType.PAGE
479480
elif obj_type in (obj_type_lib.ObjType.CALLABLE,
480481
obj_type_lib.ObjType.TYPE_ALIAS):
482+
assert self.parent is not None
481483
parent_type = obj_type_lib.ObjType.get(self.parent.py_object)
482484
if parent_type is obj_type_lib.ObjType.CLASS:
483485
return self.OutputType.FRAGMENT
@@ -589,9 +591,8 @@ def _get_physical_path(self, py_object):
589591

590592
return physical_path
591593

592-
593594
@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:
595596
"""Create an ApiTree from an PathTree.
596597
597598
Args:
@@ -615,16 +616,19 @@ def from_path_tree(cls, path_tree: PathTree, score_name_fn) -> 'ApiTree':
615616
if not duplicate_nodes:
616617
# Singleton objects will return `[]`. So look up the parent object's
617618
# duplicate nodes and collect their children.
619+
assert current_node.parent is not None
618620
parent_nodes = path_tree.nodes_for_obj(current_node.parent.py_object)
619621
duplicate_nodes = [
620622
parent_node.children[current_node.short_name]
621623
for parent_node in parent_nodes
622624
]
623625

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+
]
625629

626630
# Choose the priority name with a lexical sort on the tuples returned by
627-
# by _score_name.
631+
# _score_name.
628632
if not all(parent.path in self for parent in parents):
629633
# rewind
630634
active_nodes.appendleft(current_node)

0 commit comments

Comments
 (0)