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
Allow three-argument converters (like validators/on_setattr) #709
Comments
Maybe, converters and validators can (or event should) be merged (similarly to click callbacks)? def int_validator(self, attrib, value):
return int(value) # Validates and converts at the same time :-) I guess that would be very backwards incompatible, but maybe this can (still) be added to the new |
This is something I've been thinking about in the past days. I think a marker-wrapper for three-argument converters would be most solid and in line with our other APIs? |
There's also #146 which still bothers me that it's unresolved but to which I still don't have a good answer, 3.5 years later. :( |
Thank you for the discussion! @sscherfke I think this is kind of thing that happened to Personally I like separate validators, as they are running after all the conversions (hence - guaranteed to work with fully-initialized self!) and imply that the field value doesn't change (unless some reckless guy will do @hynek #146 is pretty informative, thank you for mentioning it! :) I actually missed the stacktrace point when I was thinking about it (and maybe some performance issues, as there is a level of indirection here...). Though, I think that having I do like the marker-wrapper idea (e.g. UPD: Just saw the comment in the PR. Actually, if |
Any update to this issue ? |
I'd like to move the discussion from converter decorator PR to this issue.
I think converters are semantically closer to
on_setattr
andvalidator
thandefault
. E.g.attr.ib(converter=...)
allows you to pass a list of callables and pipes them automatically - exactly likeattr.ib(validator=...)
andattr.ib(on_setattr=...)
and there isattr.converters
module, likeattr.setters
andattr.validators
.If we allow passing half-initialized self to converter, why don't allow full-form converters,
converter(self, attr, value)
to make them the same ason_setattr
, but for initialization?To support one, two and three-argument converters there should be either inspect-magic (in py2 - getargspec, in py3 - signature) or mandatory
Converter
wrapper for two and three-argument converters.The text was updated successfully, but these errors were encountered: