On Sat, May 7, 2022 at 6:28 AM Chris Angelico <ros...@gmail.com> wrote:
> > > 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, I really don't like this --hard to put my finger on it exactly, but I think it's because Python doesn't use any magic in method definitions. There is a touch of magic in binding methods to classes, but that comes later. so while: class Foo: def method(self, ...) Looks special, that's only because: - it's defined in the class definition directly - its using the self convention But class Foo: pass def method(fred, ...): pass Foo.method = method Means exactly the same thing. So then we have: def fun(foo, foo.bar): ... Is legal, but: def fun(this, foo, foo.bar): ... Is not. > it's the only formal argument which has a fixed definition. yes, but only in one specific context -- so I don't like it leaking out of that context. > 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 > ... > I like that -- it's simple to understand, clear, it doesn't only make sense for methods, and it might even be useful in other contexts [*]. I think: def fun(x, y.z): ... would work fine, too. e.g. you wouldn't be restricted to using other parameters. That being said, I'm still -1 on the idea. [*] -- the "other contexts" is key for me -- if someone can show that this is a useful pattern in other contexts, I think it would be a stronger proposal. -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/4OFW6LVJ5DUMUT3O7HL4FFMAUY3QKYOF/ Code of Conduct: http://python.org/psf/codeofconduct/