diff --git a/python/src/self.py b/python/src/self.py new file mode 100644 index 0000000..342ada9 --- /dev/null +++ b/python/src/self.py @@ -0,0 +1,18 @@ +# Copyright (c) 2024 RenChu Wang - All Rights Reserved + +import abc +from collections.abc import Sequence +from typing import Protocol, TypeVar + +T = TypeVar("T", bound="HasChildren", covariant=True) + + +class HasChildren(Protocol[T]): + @abc.abstractmethod + def children(self) -> Sequence[T]: ... + + +class HasSelfAsChildren(HasChildren["HasSelfAsChildren"]): + # It does autocomplete. Seems fine. + def children(self) -> Sequence["HasSelfAsChildren"]: + return []