checkcast: Provide information as to why a type is not "assignable" · Issue #16 · davidfstr/trycast (original) (raw)

Ive been using trycast for a while for runtime type checking (mostly yaml/json -> TypedDict) and its working great (thanks)

Mostly i use a pattern of checking if something is assignable and raising a TypeCastingError with the failing value to allow handling further up the stack

What would be really helpful is to be able to expose why the object is not assignable (eg "incorrect key", "incorrect type for key", "missing key" etc)

i guess there is some complexity around issues with different types of Type

implementing this might also add some complexity around continuing after the first failure and collecting the errors etc