You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can write this yourself, easily (and I have in one of my projects):
def opt(convert):
"""Invoke the subconverter only if the value is present."""
def optional_converter(val):
if val is None:
return None
return convert(val)
return optional_converter
Now, I don't think it'd be possible to use the same callable (optional) as a validator factory AND a convert factory without changes to attrs itself.
Is it, or could it be, possible to have optional type conversion using the
convert
argument, with the same logic as validation?Something like:
Apologies if it's already supported; I just don't see how in the docs.
The text was updated successfully, but these errors were encountered: