mirror of
https://github.com/theroyallab/tabbyAPI.git
synced 2026-03-15 00:07:28 +00:00
migrate to ruamel.yaml
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
"""Common utility functions"""
|
||||
|
||||
from types import NoneType
|
||||
from typing import Type, Union, get_args, get_origin
|
||||
from typing import Dict, Optional, Type, Union, get_args, get_origin, TypeVar
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
def unwrap(wrapped, default=None):
|
||||
def unwrap(wrapped: Optional[T], default: T = None) -> T:
|
||||
"""Unwrap function for Optionals."""
|
||||
if wrapped is None:
|
||||
return default
|
||||
@@ -17,13 +19,13 @@ def coalesce(*args):
|
||||
return next((arg for arg in args if arg is not None), None)
|
||||
|
||||
|
||||
def prune_dict(input_dict):
|
||||
def prune_dict(input_dict: Dict) -> Dict:
|
||||
"""Trim out instances of None from a dictionary."""
|
||||
|
||||
return {k: v for k, v in input_dict.items() if v is not None}
|
||||
|
||||
|
||||
def merge_dict(dict1, dict2):
|
||||
def merge_dict(dict1: Dict, dict2: Dict) -> Dict:
|
||||
"""Merge 2 dictionaries"""
|
||||
for key, value in dict2.items():
|
||||
if isinstance(value, dict) and key in dict1 and isinstance(dict1[key], dict):
|
||||
@@ -33,7 +35,7 @@ def merge_dict(dict1, dict2):
|
||||
return dict1
|
||||
|
||||
|
||||
def merge_dicts(*dicts):
|
||||
def merge_dicts(*dicts: Dict) -> Dict:
|
||||
"""Merge an arbitrary amount of dictionaries"""
|
||||
result = {}
|
||||
for dictionary in dicts:
|
||||
|
||||
Reference in New Issue
Block a user