On Tue, May 16, 2017 at 5:04 PM, Guido van Rossum email@example.com wrote:
What features of attrs specifically solve your use cases?
I hadn’t thought about this use case:
In : class C(): ...: x = 1 ...: ...: def __init__(self, x=None): ...: if x is not None: ...: self.x = x ...: ...: def __str__(self): ...: return 'C(%s)' % self.x ...:
In : c1 = C() ...: c2 = C(2) ...:
In : print(c1, c2) C(1) C(2)
And I might use it here on.
What I like about attrs is:
- The class level declaration of instance attributes - That the reasonable *init*, *repr*, and *eq* are generated
I don’t like the excessive wordiness in attrs, and I don’t need “the kitchen sink” be available to have instance attributes declared at the class level. A solution based on the typing module would be much better.
Basically, Python is lacking a way to declare instance fields with default values away of the initializer. Several of the mainstream OO languages (Java, Swift, Go) provide for that.
I haven’t thought much about this, except about if there’s indeed a need (and there is), but I can’t know if the solution if through decorators, or inheritance.