
On Sun, May 08, 2022 at 11:02:22AM +1000, Chris Angelico wrote:
On Sun, 8 May 2022 at 10:23, Steven D'Aprano <steve@pearwood.info> wrote:
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.
Nobody says that it makes "no sense". Stephen Turnbull suggested it doesn't make "much sense", but in context I think it is clear that he meant there are no good uses for generalising this dotted parameter name idea, not that we can't invent a meaning for the syntax.
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?
The analogy breaks down because we aren't talking about assignment targets, but function parameters. Function parameters are only *kinda sorta* like assignment targets, and the process of binding function arguments passed by the caller to those parameters is not as simple as self, x, x.y = args The interpreter also does a second pass using keyword arguments, and a third pass assigning defaults if needed. Or something like that -- I don't think the precise implementation matters. Of course we could make it work by giving *some* set of defined semantics, but unless it is actually useful, why should we bother? Hence my comment YAGNI.
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.
Power to do *what*? If nobody can think of any uses for this (beyond the auto-assignment of attributes), then what power does it really have? I don't think "power" of a programming language feature has a purely objective, precise definition. But if it did, it would surely have something to do with the ability to solve actual problems. -- Steve