28 Nov
2020
28 Nov
'20
5:22 p.m.
I think this is a perfect use case for user-defined type guards, which has been discussed in a different typing-sig thread. The draft PEP can be found [here](https://github.com/erictraut/peps/blob/master/pep-9999.rst). This is implemented in preview form within [Pyright](https://github.com/microsoft/pyright). Here's how you'd use it: ```python def is_typed_dict(raw_dict: Dict[str, Any], typed_dict_class: Type[_T]) -> TypeGuard[_T]: # Perform check here and return bool value indicating whether raw_dict # conforms to the type _T return trycast(typed_dict_class, raw_dict) is not None ```