diff --git a/.gitignore b/.gitignore index 2fc3bc5..bd975d4 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ dist/ docs/_readthedocs/ poetry.lock setup.py + +storybook/ \ No newline at end of file diff --git a/anytree/node/node.py b/anytree/node/node.py index 2ed294a..a891322 100644 --- a/anytree/node/node.py +++ b/anytree/node/node.py @@ -2,9 +2,12 @@ from .nodemixin import NodeMixin from .util import _repr +from typing import TypeVar +Child = TypeVar("Child", bound="Node") -class Node(NodeMixin): + +class Node(NodeMixin[Child]): """ A simple tree node with a `name` and any `kwargs`. diff --git a/anytree/node/nodemixin.py b/anytree/node/nodemixin.py index 46219cf..42b6703 100644 --- a/anytree/node/nodemixin.py +++ b/anytree/node/nodemixin.py @@ -8,9 +8,12 @@ from .exceptions import LoopError, TreeError from .lightnodemixin import LightNodeMixin +from typing import List, TypeVar, Generic, Union -class NodeMixin: +Child = TypeVar("Child", bound="NodeMixin") + +class NodeMixin(Generic[Child]): """ The :any:`NodeMixin` class extends any Python class to a tree node. @@ -176,7 +179,7 @@ def __children_or_empty(self): return self.__children @property - def children(self): + def children(self) -> List[Union[Child], 'NodeMixin']: """ All child nodes.