On Thu, Aug 27, 2020, 00:56 Bruce Leban <br...@leban.us> wrote:
> A bunch of the conversation here is how to handle both positional and > keyword arguments with a single signature. Let me suggest an alternative. > At compile time, we know if the call is made with keyword arguments or not. > > a[1] positional only > a[b=1] keyword only > a[1, b=1] both > a[**kwargs] keyword only > > I suggest that in the first case it calls > __getitem__(self, args) > as it does now and in the other cases it calls > __getitemx__(self, args, **kwargs) > instead (the signature is what matters here, don't bikeshed the name). > Some people have proposed arbitrary signatures for __getitemx__ but I > think that's an unnecessary degree of complexity for little benefit. > Personally, I'm not even sure I'd ever want to mix args and kwargs but > including that in the signature preserves that possibility for others that > find it useful. > > To explain further: when I use [...] without positional arguments the > code works exactly as it does today with all args in a tuple. Therefore, > for consistency when I add a keyword argument that should not change the > args value which is why both signatures include a single args parameter. > > If you write a form that uses a keyword argument, and __getitemx__ does > not exist then it would raise an error other than KeyError (either > TypeError or AttributeError, with the latter requiring no special handling). > > --- Bruce > What is the advantage of this over adding keyword arguments to the existing find dunders?
_______________________________________________ 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/7EVIBDML643EGMPM4OJXGMNMHPJ6RQSE/ Code of Conduct: http://python.org/psf/codeofconduct/