On Sat, 18 Jul 2020 at 18:31, MRAB <python@mrabarnett.plus.com> wrote:
[snip] I haven't followed this thread for a while, but, to me, it seems that the simplest option would be to pass the keyword arguments as a dict:
obj[a, b:c, x=1] does obj.__getitem__((a, slice(b, c)), dict(x=1))
If there are no keyword arguments, then there's no dict.
Could the entire argument be turned into a namedtuple? obj[a, b:c] does obj.__getitem__((a, slice(b, c)) or obj.__getitem__(namedtuple(_0=a, _1=slice(b, c))) obj[a, b:c, d=e:f] does obj.__getitem__(namedtuple(_0=a, _1=slice(b, c), d=slice(e:f))) it would seem a namedtuple is a more natural extension of the current tuple, fully backward compatible (for sane code), while allowing for keywords that are valid identifiers (which should be an acceptable limitation). The other restriction would be that the keyword-indexing cannot use all-numeric identifiers prepended by an underscore. Gerrit.