From 90bc362edd932b829e608864e71bec77158e0608 Mon Sep 17 00:00:00 2001 From: Sisung Kim Date: Thu, 26 Sep 2024 00:41:50 +0200 Subject: [PATCH 1/2] added children annotation --- anytree/node/node.py | 5 ++++- anytree/node/nodemixin.py | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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. From da5e04d3d411ec34850c536fea9151b91909ae44 Mon Sep 17 00:00:00 2001 From: Sisung Kim Date: Thu, 26 Sep 2024 03:26:22 +0200 Subject: [PATCH 2/2] added personal gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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