Python 3.10+typingfunction
typing.is_typeddict
introspection
Check whether an object is a TypedDict.
Syntax
typing.is_typeddict(tp)
It exists because neither isinstance nor issubclass work with TypedDict, and at runtime a TypedDict instance is just a plain dict, indistinguishable from any other. The function recognises the type object itself, not an instance: is_typeddict(TD) is True, but is_typeddict({'x': 1}) is False. Available since Python 3.10.
Examples
from typing import TypedDict, is_typeddict
class TD(TypedDict):
x: int
print(is_typeddict(TD)) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy