[Python-ideas] Augmented assignment syntax for objects.
Erik
python at lucidity.plus.com
Wed Apr 26 11:17:41 EDT 2017
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.
More information about the Python-ideas
mailing list