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

Closed
radix opened this Issue Sep 10, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@radix
Contributor

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.

e.g.

from pyrsistent import pmap

@attr.s
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?

@radix

This comment has been minimized.

Contributor

radix commented Sep 10, 2015

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

@hynek

This comment has been minimized.

Member

hynek commented Sep 13, 2015

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

@econchick

This comment has been minimized.

Contributor

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