On 2020-08-27 12:33 a.m., Ricky Teachey wrote:
On Wed, Aug 26, 2020 at 10:34 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Wed, Aug 26, 2020 at 12:32:56PM -0400, Ricky Teachey wrote:
> It creates a language supported way for the creator of the class to decide
> how to interpret the contents inside a subscript operation.
We already have that: `__getitem__`.
Actually no, we have THREE dunders: get, set, and del -item.
I'm not seeing what problem adding a new dunder and indirection of __*item__ solves...
Sure, on a pedantic level I had to put effort across three dunders, but the effort is a single method call *and* I would still have needed to do it in the __subscript__ scenario except I would also have to have written a __subscript__ that is a combination of _make_key and boilerplate to call the method that the interpreter would have previously called for me.
Alex