On Wed, Aug 26, 2020 at 11:03:20PM +0100, Stefano Borini wrote:
> On Wed, 26 Aug 2020 at 17:50, David Mertz <me...@gnosis.cx> wrote:
> >
> > In my mind, *anything* other than the straightforward and obvious 
> > signature `__getitem__(self, index, **kws)` is a pointless 
> > distraction.
> 
> It isn't.
> and the reason why it isn't is that it makes it much harder for the
> implementing code to decide how to proceed, for the following reasons:
> 1. you will have to check if the keywords you receive are actually in
> the acceptable set


I assumed -- possibly this was wishful thinking on my part :-) -- that 
David didn't mean *literally* only as a collection of arbitrary keywords 
`**kws` but was using that as an abbreviation for "whatever named 
keyword parameters are written in the method signature".

E.g. I can write:

    def __getitem__(self, index, *, spam, eggs=None):

to have one mandatory keyword "spam" and one optional keyword "eggs" and 
it will all Just Work. I presume that David would be good with that too, 
but if he's not, he really needs to explain why not.

Before someone else points this out, I'll mention that *technically* 
someone could use index as a keyword argument too, but so what if they 
do? However if you really want to prevent it, you can make it 
positional-only:

    def __getitem__(self, index, /, *, spam, eggs=None):

but honestly that's only necessary if you also collect arbitrary 
keywords in a `**kwargs` and want to allow "index" as one of them. 
Otherwise it's overkill.


[...]
> To me, most of the discussion is being derailed in deciding how this
> should look like on the __getitem__ end and how to implement it, but
> we haven't even decided what it should look like from the outside

Is that even a question?

    obj[index, keyword=value]

where index is any comma-separated list of expressions, including 
slices, keyword is an identifier, and value is any expression including 
slices. Are there even any other options being considered?

A few points:

- The index is optional, but it will be a runtime TypeError if the 
method isn't defined with the corresponding parameter taking a default 
value.

- You can have multiple keyword=value pairs, separated by commas. They 
must all follow the index part. Duplicate keywords is a runtime error, 
just as they are are for function calls.

- An empty subscript remains a syntax error, even if the method 
signature would allow it.


> (although it's probably in the massive number of emails I am trying to
> aggregate in the new PEP).

As PEP author, you don't have to include every little tiny detail of 
every rejected idea. It should be a summary, and it is okay to skip over 
brief ideas that went nowhere and just point back to the thread.

One of the weaknesses, in my opinion, of the existing PEP is that it 
tries to exhaustively cover every possible permutation of options (and 
in doing so, managed to skip the most useful and practical option!).

A PEP can be, and most of the time should be, an opinionated persuasive 
essay which aims to persuade the readers that your solution is the right 
solution. The PEP has to be fair to objections, but it doesn't have to 
be neutral on the issue. It shouldn't be neutral unless it is being 
written merely to document why the issue is being rejected.

So my advise is: choose the model you want, and write the PEP to 
persuade that is the best model, why the others fail to meet the 
requirements. I really hope the model you choose is the one I describe 
above, in which case I will support it, but if you hate that model and 
want something else that's your right as the PEP author.

(Although the earlier co-authors may no longer wish to be associated 
with the PEP if you change it radically.)


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

Reply via email to