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
Treatment for many and only parameters #731
Treatment for many and only parameters #731
Conversation
- A small treatment to avoid conflit with only and exclude params has been created. - An If has been created to verify if many parameter is boolean.
@sloria do you think that is a good approach? Could you(or another contributor) give me any suggestions for improvements? Thanks! |
@@ -386,6 +386,22 @@ def __init__(self, nested, default=missing_, exclude=tuple(), only=None, **kwarg | |||
self.many = kwargs.get('many', False) | |||
self.__schema = None # Cached Schema instance | |||
self.__updated_fields = False | |||
|
|||
if not isinstance(self.many, bool): | |||
raise ValueError('Many parameter must be boolean') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many
does not have to be a boolean. You can pass anything, as long as it evaluates to a either truthy value if you expect a collection or a falsy value if you expect a single element.
|
||
# Catch fields used at the same time | ||
# into only and exclude parameters | ||
fields = [item for item in only if item in list(exclude)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use set intersections to do that.
I'm not sure we're willing to add this kind of validation.
|
These seem like good warnings for new users, but would likely be burdensome errors for existing users. |
Closing this in favor of #826 |
has been created.
Related: #406