-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
deep_iterable
and deep_mapping
inconsistencies
#1206
Comments
Thanks for the summary – would you mind filing the bugs (additionally) individually, so we can check them off? Have you perchance debugged why the error message is wrong? |
Sure, will do so 👍🏼 Regarding your question about the error message: Well, I think there is just not enough context information passed when calling the validators on the individual members. I guess what we would ideally like to have is some message that provides the name of the iterable plus the index of the failing element, e.g. in this case ValueError: Length of 'x[1]' must be => 1: 0 Of cource, even better would be an ExceptionGroup that reports all failing elements, like However, these are the current two lines from for member in value:
self.member_validator(inst, attr, member) |
yes thanks we've got enough open ones 🙈 |
Hi 👋 In the last days, I noticed some inconsistent behavior of
deep_iterable
anddeep_mapping
. Some of the problems have already been mentioned in other issues (links provided below) but for others it seems there is no open issue yet. Since they are partly related, I thought it would be good to have a single overview of the necessary open fixes:Lists/tuples of validators
Some of the inner validators accept lists while others still require the explicit use of
and_
. For consistency, I think all of them should ideally be able to handle lists. For themember_validator
, the change has been in implemented in #925, butiterable_validator
still struggles with lists. For example, the following piece of code works, but replacingany_
with a list will make it fail:For
deep_mapping
, lists/tuples not supported for any of its three arguments.Typing support
When a list of validators is passed, mypy complains about the type, as already pointed out in #1197. However, when a tuple is used instead, mypy is happy.
Wrong error message
When a validation error in one of the inner validators of
deep_iterable
ordeep_mapping
occurs, an exception is thrown but the contained message is wrong. For example, using the above code and callingA(["abc", ""])
, you get the following error:It rightfully complains about the length of the second item in the list, but note that the message refers to attribute name
x
, which is incorrect, since it's notx
that is too short but one of its items.Optional validators
For
deep_iterable
, only theiterable_validator
is optional, which makes sense because if nomember_validator
was provided, one should simply use a regular validator in the first place. However, fordeep_mapping
, bothvalue_validator
andkey_validator
are required. This makes its use unnecessarily complicated in certain situations. For example, validating only dictionary keys requires a rather cumbersome workaround and also results in unnecessary calls of thevalue_validator
:Instead, I guess the user-friendly way would be to check that at least one of them is provided, but not necessarily both.
The text was updated successfully, but these errors were encountered: