From 8f6fd0e05ad6124cdad7cc047085bfd9d3f2a3e0 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 24 May 2020 18:44:28 -0700 Subject: [PATCH] functools: add TopologicalSorter for py39 (#4068) * functools: add TopologicalSorter for py39 * fix flake8 error Co-authored-by: hauntsaninja <> --- stdlib/3/functools.pyi | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stdlib/3/functools.pyi b/stdlib/3/functools.pyi index 10469c183..515f3f1ee 100644 --- a/stdlib/3/functools.pyi +++ b/stdlib/3/functools.pyi @@ -97,3 +97,15 @@ if sys.version_info >= (3, 8): @overload def __get__(self, instance: _S, owner: Optional[Type[Any]] = ...) -> _T: ... def __set_name__(self, owner: Type[Any], name: str) -> None: ... + +if sys.version_info >= (3, 9): + class TopologicalSorter(Generic[_T]): + def __init__(self, graph: Optional[Dict[_T, Iterable[_T]]] = ...) -> None: ... + def add(self, node: _T, *predecessors: _T) -> None: ... + def prepare(self) -> None: ... + def is_active(self) -> bool: ... + def done(self, *nodes: _T) -> None: ... + def get_ready(self) -> Tuple[_T, ...]: ... + def static_order(self) -> Iterable[_T]: ... + + class CycleError(ValueError): ...