On Sat, 18 Jul 2020 at 18:31, MRAB <pyt...@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.
_______________________________________________
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/ZZDIVLUFIM2B45BRVQAZ5EMFKJQ6IJTL/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to