-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Add IP address field type. #1485
Conversation
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.
Should we add a parameter to only accept IPv4 or IPv6 rather than accepting any?
Should we also provide IPv4
and IPv6
fields as a shortcut?
Also, I don't see the point of the _serialize
method. Apparently you copied it from an already existing field (UUID
) so it's nothing new. But this seems a bit dodgy to me. Let's discuss this in #1489.
That is correct, I've overridden the |
Also please note that exploded notation is specific for IPv6 addresses, but the argument is also present in IPv4 constructor. This feature is sourced from |
Would it make sense to implement these as validators? That would allow combining with other validators. |
I have to admit that maybe I was too inspired by the implementation of the
Also, I can see, that Returning to the case of the UUID field. Maybe it should be discussed whether it should inherit from I am also wondering whether IP specific validators are welcome? Based on |
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.
Looks good to me.
Just a question/comment about a test. I wouldn't mind another opinion here.
Your remarks about UUID field make sense. Reworking it could be done in another PR, and perhaps in marshmallow 4 if it is a breaking change.
IP specific validation welcome. Should those be field constructor arguments instead like exploded?
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.
LGTM. I'm just concerned about the code duplication. Could _deserialize
be factorized, using class attributes for the object class, like what is done for the error message? (The typing would be a little less strict, but oh well.)
I've tried to define class variable typed as
but I'm not entirely comfortable with such construct. Also, mypy doesn't like it as well since there is unresolved issue #3482 which is of relevance for class methods and static methods defined this way. |
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.
Sorry for the delay and thanks for your work on this.
@lafrech I didn't to a fine-toothed review of this, but it looked good last time I looked. I defer to you on merging this. |
Merged and released. Thanks again @mgetka. |
This pull request adds IPv4/IPv6 fields serialization and deserialization w/ tests included. To avoid confusion I am excluding the possibility to specify IP addresses as an integer or byte values.