On Sat, Aug 29, 2020, at 20:14, Greg Ewing wrote:
> I think this could be done more simply as
> 
>      def __getitem__(self, index, **kwds):
>          self.real_getitem(*index, **kwds)
> 
>      def real_getitem(self, x, y):
>          ...
> 
> The point about obscuring the signature still remains, though.
> 
> Also, this is a hack that we would never be able to get rid of,
> whereas new dunders would provide a path to cleaning things up
> in the future.

The thing that bothers me with new dunders is - can it be done in such a way 
that *all* possible ways of calling it with only positional arguments behave 
the same as presently when the old one is defined, and an intuitive way with 
the new one, without requiring the calling bytecode to know which signature is 
going to be used?

__getitem__(self, arg) vs __getitem_ex__(self, *args, **kwargs)

x[1] - old arg=1; new args=(1,)
x[1,] - old arg=(1,); new args=(1,)?
x[(1,)] old arg=(1,); new args=((1,),)?
x[1,2] old arg=(1,2); new args=(1,2)
x[(1,2)] old arg=(1,2); new args=((1,2),)?
x[*a] old arg=a new args=a?

Also, do we want to walk the MRO looking for both in turn, or look for the new 
one on the whole chain before then looking for the old one? is there a 
precedent for two different ways to define a method on a single class? [getattr 
vs getattribute is not a case of this, and i say "single class" to exclude the 
complexity of binary operators]

Another concern is where a new setitem should put the value argument? i may 
have missed something mentioning it, but I don't think I've seen a proposal 
that goes into detail on that? Having the user define a __setitem__ that calls 
the real_setitem if needed gets around that by leaving the signature up to the 
user [where they can e.g. put it in a keyword arg with a name they know they 
won't need]
_______________________________________________
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/IOMTOY43LUFBXJS2PYHR2FMCHFCI2NNK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to