On Mon, Aug 03, 2020 at 05:20:25PM -0400, Todd wrote:
> Another approach could be too simply pass the labelled indices in a dict as
> a third/fourth positional argument.

Why would we want to even consider a new approach to handling keyword 
arguments which applies only to three dunder methods, `__getitem__`, 
`__setitem__` and `__delitem__`, instead of handling keyword arguments 
in the same way that every other method handles them?

That's not a rhetorical question. If there is an advantage to making 
this a special case, instead of just following the same rules as all 
other methods, I'm open to hearing why it should be treated as a special 
case.


> So for indexing
> 
> b = arr[1, 2, a=3, b=4]
> 
> Instead of
> 
> __getitem__(self, (1, 2), a=3, b=4)
> 
> Just do
> 
> __getitem__(self, (1, 2), {'a': 3, 'b': 4})

That would be the effect of defining your method with signature:

    def __getitem__(self, index, **kwargs)

so if you specifically want all your keyword arguments bundled into a 
dict, you can easily get it.



-- 
Steven
_______________________________________________
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/RJGNYW6LH4VPSO2HULRLYKXBN5WSZTBT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to