On Sat, 7 May 2022 at 23:15, Stephen J. Turnbull <stephenjturnb...@gmail.com> wrote: > > Steven D'Aprano writes: > > > What would this do? > > > > def __init__(self, spam.x, eggs.y): pass > > > > How about this? > > > > def __init__(self, x, x.y): pass > > IMO, both of those should be errors. This syntax only makes much > sense for the first formal argument of a method definition, because > it's the only formal argument which has a fixed definition. The form > "def foo(self, x, x.y)" has an interpretation, I guess, but > > def foo(self, x, y): > x.y = y > > is not a pattern I can recall ever seeing, and it could be relatively > easily relaxed if it were requested enough. On the other hand, folks > do frequently request a way to DRY out long suites of "self.x = x" > assignments. >
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 ... The logical extension to kwargs would work in natural parallel. ChrisA _______________________________________________ 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/PAG2UK5FY4DRZZHM2VH6AHZC22GGFWF2/ Code of Conduct: http://python.org/psf/codeofconduct/