I have this code:
from typing import Tuple, Dict, List
CoordinatesType = List[Dict[str, Tuple[int, int]]]
coordinates: CoordinatesType = [
{"coord_one": (1, 2), "coord_two": (3, 5)},
{"coord_one": (0, 1), "coord_two": (2, 5)},
]
I would like to check at runtime if my variable fits my custom type definition. I was thinking on something like:
def check_type(instance, type_definition) -> bool:
return isinstance(instance, type_definition)
But obviously isinstance is not working.
I need to check this at runtime, what would be the correct way to implement it?
Typeguard:https://typeguard.readthedocs.io/en/latest/userguide.html#using-type-checker-functionsExample:
code:
result: