Skip to content
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
Closed

Allow conversion of parameters #26

radix opened this issue Sep 10, 2015 · 3 comments

Comments

@radix
Copy link
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
Copy link
Contributor Author

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
Copy link
Member

hynek commented Sep 13, 2015

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

@econchick
Copy link
Contributor

Omg I need this feature. NEED.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants