On Sat, May 07, 2022 at 11:38:19AM -0700, Ethan Furman wrote:

> > I'd define it very simply. For positional args, these should be
> > exactly equivalent:
> >
> > def func(self, x, x.y):
> >      ...
> >
> > def func(*args):
> >      self, x, x.y = args
> >      ...
> 
> Simple or not, I don't think Python needs that much magic.

Indeed. Just because we can imagine semantics for some syntax, doesn't 
make it useful. Aside from the very special case of attribute binding in 
initialisation methods (usually `__init__`), and not even all, or even a 
majority, of those, this is a great example of YAGNI.

Outside of that narrow example of auto-assignment of attributes, can 
anyone think of a use-case for this?

And as far as auto-assignment of attributes goes, I want to remind 
everyone that we have that already, in a simple two-liner:

    vars(self).update(locals())
    del self.self

which will work for most practical cases where auto-assignment would be 
useful. (It doesn't work with slots though.)

This is a useful technique that isn't widely known enough. I believe 
that if it were more widely know, we wouldn't be having this discussion 
at all.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/CTVO5ZA2XUYZTG45DP6HPFQNQOKJKXP7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to