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 conversion of parameters #26

radix opened this Issue Sep 10, 2015 · 3 comments


None yet
3 participants

radix commented Sep 10, 2015

I'd personally be able to get rid of a lot of boilerplate (either at call sites or as __init__ methods) from my classes if attrs allowed me to supply a conversion callable with my attr.ibs.


from pyrsistent import pmap

class Foo(object):
    mapping = attr.ib(coerce=pmap)

The coerce argument (naming to be bikeshedded) would be called with the value passed in after validation, and the return value would be used as the actual attribute value.

Would such a feature be accepted as a patch?


This comment has been minimized.


radix commented Sep 10, 2015

or... maybe coerce should happen before validation. maybe that is one reason why this hasn't been done yet :)


This comment has been minimized.


hynek commented Sep 13, 2015

Maybe a more generic name like "hook" would be more apt?


This comment has been minimized.


econchick commented Sep 13, 2015

Omg I need this feature. NEED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment