Thanks Eric,

On Fri, Sep 25, 2020 at 09:23:56AM +0100, Eric Wieser wrote:
> Thanks for the PEP, and for pinging the numpy list about it. Some comments:
> 
> Sequence unpacking remains a syntax error inside subscripts:
> Reason: unpacking items would result it being immediately repacked into a
> tuple
> 
> A simple counter-example is [:, *args, :], which could be treated as
> [(slice(None), *args, slice(None))].
> When there are index objects to the left or right of *args, it enables :
> syntax in places that would otherwise be forbidden.

This use-case is persuasive to me.

I recommend that the PEP be changed to allow `*args` inside subscripts.


> Keyword-only subscripts are permitted. The positional index will be the
> empty tuple
> 
> As discussed on the numpy mailing list, a better approach might be to not
> pass an argument at all, so that obj[spam=1, eggs=2] calls
> type(obj).__getitem__(obj, spam=1, eggs=2).
> Objects which want to support keyword-only indexing can provide a default
> of their own (and are free to choose between () and None, while objects
> which do not would just raise TypeError due to the missing positional
> argument

That's fine for getitem and delitem, but doesn't work with setitem.


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

Reply via email to