-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More explicit TypeMisMatch errors #111
Labels
enhancement_medium
A feature or request which should be adopted with medium priority
Projects
Comments
I hope you agree on the following solution. <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?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!!!
The text was updated successfully, but these errors were encountered: