Open frallain opened 1 year ago
I hope you agree on the following solution. This is an example error message
<class '__main__.Regisseur'>
parameter `movie` is invalid:
it contains value `<class '__main__.Movie'>` which is not of type `typing_extensions.Required[dict[strongtyping.strong_typing.Movie]]`
If you capture the exception you can access all interesting informations
@match_class_typing
class Movie(TypedDict):
title: str
year: NotRequired[int]
@match_class_typing
class Additional(TypedDict):
name: str
val: NotRequired[str]
@match_class_typing
class Regisseur(TypedDict):
name: str
movie: Required[dict[Movie]]
year: Required[int]
info: NotRequired[dict[Additional]]
def main():
try:
print(Regisseur(name="Alfonso Cuarón", movie=Movie, year=2004))
except TypeMisMatch as err:
print(err.exception_info.issues)
print(err.param_values)
print(err.failed_params)
print(err.annotations)
if __name__ == "__main__":
main()
err.exception_info.issues = defaultdict(<class 'dict'>, {'movie': {0: [(<strongtyping.strong_typing.MatchTypedDict object at 0x7eff912c4460>, typing_extensions.Required[dict[strongtyping.strong_typing.Movie]])]}})
err.param_values = dict_keys(['name', 'movie', 'year', 'info'])
err.failed_params = {'name': 'Alfonso Cuarón', 'movie': <strongtyping.strong_typing.MatchTypedDict object at 0x7eff912c4460>, 'year': 2004}
err.annotations = dict_values([<class 'str'>, typing_extensions.Required[dict[strongtyping.strong_typing.Movie]], typing_extensions.Required[int], typing_extensions.NotRequired[dict[strongtyping.strong_typing.Additional]]])
@frallain what do you say to my suggestion??
Python Version used Python 3.10.4 (main, May 28 2022, 13:25:38) [GCC 10.2.1 20210110] on linux
Package Version used strongtyping 3.10.4
Addon in use strongtyping_modules [yes/no]
To Reproduce
gives
Expected behavior A clearer error message on which attributes are missing/extra/have wrong types e.g.
Thanks again for your work!!!