On Wed, Aug 26, 2020 at 9:00 PM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
> On 27/08/20 3:51 am, Ricky Teachey wrote: > > On Wed, Aug 26, 2020 at 11:30 AM Greg Ewing <greg.ew...@canterbury.ac.nz > > <mailto:greg.ew...@canterbury.ac.nz>> wrote: > > > > No, it would be done by checking type slots, no MRO search involved. > > > > Can you elaborate on this for my understanding? > > For frequently-used special methods such as __getitem__, the type > object contains direct pointers to C functions (so-called "type slots"). > ... > The overhead for this would be just one extra C pointer check, which > you would be hard-pressed to measure. > Wow that's great news. > > the index operator recognizes this as a tuple: > > > > 1, > > > > But function calls do not. > > We could probably cope with that by generating different bytecode > when there is a single argument with a trailing comma, so that a > runtime decision can be made as to whether to tupleify it. > > However, I'm not sure whether it's necessary to go that far. The > important thing isn't to make the indexing syntax exactly match > function call syntax, it's to pass multiple indexes as positional > arguments to __getindex__. So I'd be fine with having to write > a[(1,)] to get a one-element tuple in both the old and new cases. > > It might actually be better that way, because having trailing > commas mean different things depending on the type of object > being indexed could be quite confusing. > > -- > Greg > I didn't know that was possible. It's far beyond my knowledge. The idea of a new dunder is starting to sound like a much more realistic possibility than I had hoped. --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler
_______________________________________________ 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/XNQENI43SIACJNRY522ILERSNSNITF2J/ Code of Conduct: http://python.org/psf/codeofconduct/