Skip to content
Commit c6bb336b authored by Martí Bolívar's avatar Martí Bolívar Committed by Kumar Gala
Browse files

dtlib: add type checking for DT.root



We'd like users of this API to know that DT.root is always a Node,
and not an Optional[Node].

However, although DT.__init__ throws an exception if the resulting DT
object would have no root node, static analysis can't tell that since
the root instance attribute starts out as None during initialization,
so checkers like mypy are convinced it's Optional[Node].

Since this is really OK, we'll quiet the type checker down by stashing
the instance attribute in self._root instead, and providing a root
property accessor that is annotated to return Node instead of
Optional[Node]. We can tell mypy to ignore what looks like a potential
None here to allow callers to treat the result as a Node.

Signed-off-by: default avatarMartí Bolívar <marti.bolivar@nordicsemi.no>
parent b13b5b8b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment