-
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
Are there errors for undefined keys? #129
Comments
@yupix Thank you for using DeepL for easier communication. The current behavior is that you won't get any exceptions if you have an undefined
or
what did you say to the solution ideas?? |
Thanks for the quick reply. I think the first code is better in my opinion.
|
Could you please tell me which Python version you're using? I will then extend the decorator to support this will be the TestCase: def test_undefined_keys_raise_error():
@match_class_typing(throw_on_undefined=True)
class User(TypedDict):
id: str
username: str
description: str | None
with pytest.raises(UndefinedKey):
User({"id": "0123", "username": "test", "description": None, "age": 10})
assert User({"id": "0123", "username": "test", "description": None}) |
The project I am creating is currently using Python 3.11 and will change to 3.12 on January 2 next year, three months after the release of 3.12. Therefore, it would be helpful if you could implement this project in Python 3.11 if possible. As for the testing, I think it is good. |
feature is now available at https://pypi.org/project/strongtyping/3.12.1/ |
First of all, thank you for creating such a useful library.
Is it possible to return an exception for undefined keys?
As an example, if I pass a dict to
User
with a keyage
that I have not defined, it will return an exception.The reason I want this feature is to help find things that are not defined in the TypedDict. It would be nice to be able to log warnings, etc. even if they are not exceptions.
Due to my inexperience with English, I am using DeepL. I apologize if you find anything offensive.
The text was updated successfully, but these errors were encountered: