On Wed, Aug 26, 2020 at 10:10 AM Ricky Teachey <ri...@teachey.org> wrote:
> *Objection 1: Slowing Things Down* > ...for actual implementation... we could wrap the existing item dunder > methods automatically at class creation time only when the new dunder > attribute is present. If it is not present, nothing happens. In other > words, what has been described as the "default key or index > translation function" already exists. Let's not change that at all for > classes that do not choose to use it. > After reading Steve's response to me in the other thread, where he says this: On Wed, Aug 26, 2020 at 9:48 AM Steven D'Aprano <st...@pearwood.info> wrote: > On Tue, Aug 25, 2020 at 10:51:42PM -0400, Ricky Teachey wrote: > > > Well it would not have to inspect the signature on every subscript call, > > Python is a very dynamic language and objects can change their own > methods and even their class at any time, so, yes, it will have to > inspect the signature on every call. Otherwise you are changing > the language execution model. > > Demonstration: > > > py> class Dynamic: > ... def __getitem__(self, arg): > ... print("original") > ... type(self).__getitem__ = lambda *args: > print("replaced") > ... > py> > py> x = Dynamic() > py> x[0] > original > py> x[0] > replaced > ...I am less optimistic that this can be implemented without slowing things down. And wrapping the methods at class creation time may not be a good idea after all. I am a little crestfallen now, because I still think the core of the idea is a wonderful idea. Is there another clever way this could be implemented, to avoid the slowdown of existing code? --- 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/6XIRDYIQAJMQJOZQX4DUTNHLWPKSIS6V/ Code of Conduct: http://python.org/psf/codeofconduct/