On 26/04/17 08:59, Paul Moore wrote:
It should be possible to modify the decorator to take a list
of the variable names you want to assign, but I suspect you won't like
that
Now you're second-guessing me.
> class MyClass:
> @auto_args('a', 'b')
> def __init__(self, a, b, c=None):
> pass
I had forgotten that decorators could take parameters. Something like
that pretty much ticks the boxes for me.
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
;)), 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 ;)
E.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/