diff options
author | Devaev Maxim <[email protected]> | 2020-09-10 07:30:25 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-09-10 07:30:25 +0300 |
commit | 967afb2d9a0f4a94026ec612801b6291db5c6a72 (patch) | |
tree | 70823828e4a3f215e055df5b8cda36c0adbed691 /kvmd/tools.py | |
parent | a6385cd20e4c4119d9679ed6a58fd9e302d10efe (diff) |
refactoring
Diffstat (limited to 'kvmd/tools.py')
-rw-r--r-- | kvmd/tools.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/kvmd/tools.py b/kvmd/tools.py index 1259893c..6d10e227 100644 --- a/kvmd/tools.py +++ b/kvmd/tools.py @@ -20,10 +20,14 @@ # ========================================================================== # +import operator import functools +from typing import Tuple +from typing import List from typing import Dict from typing import Hashable +from typing import TypeVar # ===== @@ -41,3 +45,11 @@ def rget(dct: Dict, *keys: Hashable) -> Dict: if not isinstance(result, dict): raise TypeError(f"Not a dict as result: {result!r} from {dct!r} at {list(keys)}") return result + + +_DictKeyT = TypeVar("_DictKeyT") +_DictValueT = TypeVar("_DictValueT") + + +def sorted_kvs(dct: Dict[_DictKeyT, _DictValueT]) -> List[Tuple[_DictKeyT, _DictValueT]]: + return sorted(dct.items(), key=operator.itemgetter(0)) |