On Wed, Apr 26, 2017 at 6:57 PM, Mike Miller <python-ideas@mgmiller.net> wrote:
Yes, I like it too.  Removes the triple repetition, and has precedent in the other languages.

This discussion has been around how to deal with repetition in object constructors, and the proposals have been a new assignment statement (patch assignments?) or decorators to __init__ (patch init).

In my experience, what Python is lacking is a way to declare attributes outside of the constructor. Take a look at how it's done in C#, Swisft, or Go.

Object attributes outside of the constructor would solve things more relevant than the vertical space used when assigning constructor parameters to attributes. For example, multiple inheritance is well designed in Python, except that it often requires constructors with no parameters, which leads to objects with no default attributes.

The namespace after "class"  is taken by class attributes. There's no namespace for default object attributes outside __init__. Solving that would likely lead to simple and sensible solutions to the OPs query.

I don't think that a solution to the OPs query should be treated as a No-No, because there's namedtuple, which is quirky, but solved lots of use cases (the same goes for Enum).

IMHO, something like the attrs library solves lots of common use cases... except that tool support is poor because attrs is not part of stdlib.

It is not about having to write a few more lines in an __init__ constructor. There are common and frequent use cases of "objects are mostly data" that are partially solved in Python (mostly through namedtuple?).

Cheers!

--
Juancarlo Añez