On Wed, Apr 26, 2017 at 11:17 AM, Erik <python@lucidity.plus.com> wrote:
I had forgotten that decorators could take parameters. Something like that pretty much ticks the boxes for me.

There are decorators with "include"  and "included" in this SO Q&A:

    http://stackoverflow.com/q/3652851/545637
 
I'd _prefer_ something that sits inside the method body rather than just outside it, and I'd probably _prefer_ something that wasn't quite so heavyweight at runtime (which may be an irrational concern on my part ;)),

The same strategies applied by the decorators may be applied by a by a function called from within __init__.
 
but those aren't deal breakers, depending on the project - and the vast majority of what I do in Python is short-lived one-off projects and rapid prototyping for later implementation in another language, so I do seem to be fleshing out a set of classes from scratch and writing a bunch of __init__ methods far more of the time than people with long-lived projects would do. Perhaps that's why it irritates me more than it does some others ;)

For the cases I've found in which classes define several attributes that are initialized in the constructor I think that a library like https://github.com/python-attrs/attrs does what's needed. The downside is that code-writing tools (like IDEs) don't understand what's going on under the hood.

--
Juancarlo Añez