From e815c803a6f9659df025c38d79d28db396861ebc Mon Sep 17 00:00:00 2001 From: speezepearson Date: Wed, 13 Jul 2016 06:16:37 -0700 Subject: [PATCH] add ChainMap class to collections module (#361) * add ChainMap class to collections module * ...and add it for Python 2 as well. --- stdlib/2.7/collections.pyi | 14 ++++++++++++++ stdlib/3/collections/__init__.pyi | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/stdlib/2.7/collections.pyi b/stdlib/2.7/collections.pyi index 9b6bc4d07..9d4624301 100644 --- a/stdlib/2.7/collections.pyi +++ b/stdlib/2.7/collections.pyi @@ -90,3 +90,17 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def __init__(self, default_factory: Callable[[], _VT], iterable: Iterable[Tuple[_KT, _VT]]) -> None: ... def __missing__(self, key: _KT) -> _VT: ... + +class ChainMap(Dict[_KT, _VT], Generic[_KT, _VT]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... + + @property + def maps(self) -> List[Mapping[_KT, _VT]]: ... + + def new_child(self, m: Mapping[_KT, _VT] = ...) -> ChainMap[_KT, _VT]: ... + + @property + def parents(self) -> ChainMap[_KT, _VT]: ... diff --git a/stdlib/3/collections/__init__.pyi b/stdlib/3/collections/__init__.pyi index cb3215101..6e741006f 100644 --- a/stdlib/3/collections/__init__.pyi +++ b/stdlib/3/collections/__init__.pyi @@ -133,3 +133,17 @@ class defaultdict(Dict[_KT, _VT], Generic[_KT, _VT]): def __missing__(self, key: _KT) -> _VT: ... # TODO __reversed__ + +class ChainMap(Dict[_KT, _VT], Generic[_KT, _VT]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, *maps: Mapping[_KT, _VT]) -> None: ... + + @property + def maps(self) -> List[Mapping[_KT, _VT]]: ... + + def new_child(self, m: Mapping[_KT, _VT] = ...) -> ChainMap[_KT, _VT]: ... + + @property + def parents(self) -> ChainMap[_KT, _VT]: ...