
Another approach could be too simply pass the labelled indices in a dict as a third/fourth positional argument. 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}) On Mon, Aug 3, 2020, 16:46 Christopher Barker <pythonchb@gmail.com> wrote:
Yes, that would be correct. However, the function could instead be defined
as:
def __getitem__(self, index, /, **kwargs): ...
and then there'd be no conflict (as "self" and "index" must be passed positionally). In effect, the naive spelling (which permits self and index to be passed as keywords) would be a subtle bug that could easily be corrected.
sure, but it would be a bug in a LOT of existing code!
I wonder, if this were to be introduced, if the interpreter could have a special case that would call __getitem__ in a special way to avoid this bug in old code.
-CHB
-- Christopher Barker, PhD
Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-leave@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/GL3ZVH... Code of Conduct: http://python.org/psf/codeofconduct/