On Wed, Aug 26, 2020 at 11:31:25AM +1200, Greg Ewing wrote: > I think an argument can be made that the new dunder -- let's call > it __getindex__ for now -- shouldn't be considered part of the > mapping protocol. It's a new thing for classes that want to use the > indexing notation in ways that don't fit the simple idea of mapping a > key object to a value object.
Most existing uses of subscripts already don't fit that key:value mapping idea, starting with lists and tuples. Given `obj[spam]`, how does the interpreter know whether to call `__getitem__` or `__getindex__`? What if the class defines both? > The only drawback I can think of right now is that it would make > possible objects for which x[1, 2] and x[(1, 2)] were not equivalent. Right now, both sets of syntax mean the same thing and call the same method, so you are introducing a backwards incompatible change that will break code. Can we postpone this proposal for Python 6000 in 2050? -- Steve _______________________________________________ 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/5BK6FJZY54QENLZ5N6VQEJM62UTURAWQ/ Code of Conduct: http://python.org/psf/codeofconduct/