Skip to content

Commit

Permalink
fix: type casting
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarble committed Sep 19, 2021
1 parent 0e04ed5 commit 03570d6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions datadis/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List, Mapping, TypedDict
from typing import Any, Iterable, List, Mapping, Type, TypeVar, TypedDict


class Supplie(TypedDict):
Expand Down Expand Up @@ -38,8 +38,11 @@ class ConsumptionData(TypedDict):
obtainMethod: str


def dict_to_typed(data: Mapping[str, Any], typed: TypedDict) -> TypedDict:
result = typed()
T = TypeVar('T', Supplie, ConsumptionData, ContractDetail)


def dict_to_typed(data: Mapping[str, Any], typed: Type[T]) -> T:
result: T = typed.__call__()
for key, _ in typed.__annotations__.items():
if key not in data:
raise ValueError(f"Key: {key} is not available in data.")
Expand Down

0 comments on commit 03570d6

Please sign in to comment.