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

Provide a way to have attributes that have an inital value, but no keyword argument. #19

Closed
tomprince opened this issue Jul 14, 2015 · 3 comments

Comments

@tomprince
Copy link
Contributor

Given that attrs doesn't allow composing with a custom __init__, there is no way to initialize mutable implementation details.

For example,

class Pool(object):
   def __init__(self, pool_size):
       self.pool_size = pool_size
       self._pool = []
    ...

can't be expressed with attrs.

@hynek
Copy link
Member

hynek commented Jul 14, 2015

_pool = attr.ib(default=attr.Factory(list)) is what I use.

Maybe I could support init=False such that it’s actually impossible to pass values for it? In my internal software I don’t care and just don’t pass anything, but if you’re building public APIs I see the value.

OTOH, I have written custom __init__s before. In the end it’s more readable than giving 1000s of options and variations to hit every single edge-case.

@hynek
Copy link
Member

hynek commented Dec 19, 2015

Is #32 an adequate solution to your problem?

@tomprince
Copy link
Contributor Author

It looks like it is.

@hynek hynek closed this as completed Dec 20, 2015
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

2 participants