Coverage for phml\utilities\misc\__init__.py: 100%
15 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-06 16:37 -0500
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-06 16:37 -0500
1"""phml.utilities.misc
3Helpful utilities for different tasks that doesn't have a place in the other categories.
4"""
6from phml.nodes import Parent
8from .classes import *
9from .heading import *
12def depth(node) -> int:
13 """Get the depth in the tree for a given node.
15 -1 means that you passed in the tree itself and you are at the
16 ast's root.
17 """
19 level = -1
20 while node.parent is not None:
21 level += 1
22 node = node.parent
24 return level
27def size(node: Parent) -> int:
28 """Get the number of nodes recursively."""
29 from phml.utilities import walk # pylint: disable=import-outside-toplevel
31 count = 0
33 for _ in walk(node):
34 count += 1
36 return count