Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added children annotation #267

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ dist/
docs/_readthedocs/
poetry.lock
setup.py

storybook/
5 changes: 4 additions & 1 deletion anytree/node/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
7 changes: 5 additions & 2 deletions anytree/node/nodemixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down