in chz/validators.py [0:0]
def typecheck(self: Any, attr: str) -> None:
"""A fancy type check based on the annotated type of the field."""
field = self.__chz_fields__[attr.removeprefix("X_")]
typ = field.x_type
value = getattr(self, attr)
if not is_subtype_instance(value, typ):
# TODO: is_subtype_instance is in a much better place to return diagnostics
if getattr(typ, "__origin__", None) is Literal:
raise TypeError(f"Expected {attr} to be {type_repr(typ)}, got {value!r}")
raise TypeError(
f"Expected {attr} to be {type_repr(typ)}, got {type_repr(_simplistic_type_of_value(value))}"
)