
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