
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. This could, of course, be done with a symbol such as '@' or even '.', but '@' could also be used for other purposes (late binding, for example), and "def foo(self, .x, .y):" looks like both grit on Tim's screen and a typo. On the other hand, I can't imagine what else might be meant by "def foo(self, self.x):". All that said, I'm not a fan of this feature as such. But giving this semantics to formal arguments of the form "self.x" is the most intuitive (in the sense of "hard to give another interpretation") of the proposals I've seen.