RE: empty subscripts: Should something[] be allowed syntax?
TL;DR: no In a way this comes down to design philosophy vs implementation. >From an implementation perspective, the [] operator is another way to call __getitem__ and __setitem__. And from that perspective, why not have it act like a function call: no arguments, positional arguments, keyword arguments, the whole shebang. But from a language design perspective, the [] operator is a way to "index" a container -- get part of the container's contents. And from this perspective, no index makes no sense. I like to think of the dunders as an implementation detail, so no, the square brackets have a distinct meaning that is different from the parentheses, and should not have the same features. another way to think of it is that we shouldn't encourage folks to "abuse" the [] as simply an alternative way to call the object. -CHB On Mon, Aug 17, 2020 at 4:06 AM Antoine Pitrou <solip...@pitrou.net> wrote: > On Mon, 17 Aug 2020 22:54:32 +1200 > > Greg Ewing <greg.ew...@canterbury.ac.nz> wrote: > > > On 17/08/20 9:58 pm, Antoine Pitrou wrote: > > > > Probably because exploiting Python abstraction facilities to build DSLs > > > > has/had long been frown upon in this community? That was the leitmotiv > > > > back when people were marvelling over Ruby's flexibility in the area. > > > > > > As far as I remember, what was frowned on was adding weird and > > > wonderful syntax (e.g. function calls without parens) to Python > > > purely because "it might be useful for DSLs". > > > > Notice that such weird and wonderful syntax was proposed again by Guido > > recently... > > > > And as I said, annotations have become a DSL in themselves, and several > > PEPs are dedicated to that DSL. > > > > > There's nothing > > > wrong with using existing features to build DSLs (although > > > people might look askance at you if you use them in particularly > > > obscure ways). > > > > Well, we're not talking about an existing feature in this thread. > > > > Regards > > > > Antoins. > > > > _______________________________________________ > > 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/SZQUVE3TQEJARYLPPKI63TKEVTFBWPDH/ > > Code of Conduct: http://python.org/psf/codeofconduct/ > >
_______________________________________________ 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/ODY5IXVXMTQUUY5JMNO4U6PONGPRDYWK/ Code of Conduct: http://python.org/psf/codeofconduct/