summaryrefslogtreecommitdiff
path: root/kvmd/tools.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-10 07:30:25 +0300
committerDevaev Maxim <[email protected]>2020-09-10 07:30:25 +0300
commit967afb2d9a0f4a94026ec612801b6291db5c6a72 (patch)
tree70823828e4a3f215e055df5b8cda36c0adbed691 /kvmd/tools.py
parenta6385cd20e4c4119d9679ed6a58fd9e302d10efe (diff)
refactoring
Diffstat (limited to 'kvmd/tools.py')
-rw-r--r--kvmd/tools.py12
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))