
On Sun, 8 May 2022 at 10:23, Steven D'Aprano <steve@pearwood.info> wrote:
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?
Honestly, I don't know of any. But in response to the objection that it makes no sense, I offer the perfectly reasonable suggestion that it could behave identically to other multiple assignment in Python. There's not a lot of places where people use "for x, x.y in iterable", but it's perfectly legal. Do we need a use-case for that one to justify having it, or is it justified by the simple logic that assignment targets are populated from left to right? I'm not advocating for this, but it shouldn't be pooh-poohed just because it has more power than you personally can think of uses for. ChrisA