Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
fields.Function should support func=None #325
I see the fields.Function being pretty useful with in webargs which presently only deals with deserialization. Unfortunately at the moment I have to provide a dummy function for the func argument or I'll hit an exception. It's entirely possible that there's a better field type within Marshmallow for addressing this but I don't think so.
I have a bit of a question mark around whether it makes sense to maintain backward compatibility and leave the signature as is:
class Function(object): def __init__(self, func, deserialize=None, **kwargs): # func is allowed to be None ...
or shift to something like
class Function(object): def __init__(self, serialize=None, deserialize=None, **kwargs): ...
which obviously isn't backward compatible but provides a clearer interface. Also, there's a bit of a question mark around whether the class should raise an exception if both serialize and deserialize are missing or whether it should just continue on despite being useless - probably an exception makes sense.
Happy to provide a PR should this change be acceptable.
I am open to this. We need to maintain backwards compatibility with the
Yes, I think it makes sense for an exception to be raised if both are omitted.
On a related note: I think it would make sense to set