[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-29 Thread Steven D'Aprano
On Mon, Sep 28, 2020 at 08:19:01PM -0700, Ben Rudiak-Gould wrote: > Maybe a singleton that supported no useful operations, not even __eq__ or > __bool__, would be sufficiently inconvenient that it would only be used for > defaults and "is" tests for said defaults. NotImplemented is halfway there:

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Greg Ewing
On 29/09/20 4:19 pm, Ben Rudiak-Gould wrote: it's worth mentioning that Haskell has tuples of length 0, 2, 3, ..., but no tuples of length 1. Tuples are meant for putting n values where 1 value is expected, and when n=1 you just put the value there. To elaborate on that a bit, the length of a

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Ben Rudiak-Gould
On Sun, Sep 27, 2020 at 2:18 PM MRAB wrote: > Consider, for example, the use-case of a function that has an optional > parameter and you want a way to know whether an argument has been > provided but None is a valid value that could be passed in. > > Having a singleton such as Missing would be he

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Stefano Borini
On Mon, 28 Sep 2020 at 15:45, Eric Wieser wrote: > > Would another option be to just stop using the tuple-less index in the > presence of new syntax - so by example, I don't think it would be a reliable approach. Now you end up with a "randomly" occurring special case depending on how it's invok

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread MRAB
On 2020-09-28 06:51, Chris Angelico wrote: On Mon, Sep 28, 2020 at 3:33 PM Christopher Barker wrote: As for using an empty tuple, thanks Guido for laying out the logic so succinctly, and it does make it pretty simple that only the one index case is special. Nevertheless, I think most folks ex

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-28 Thread Eric Wieser
Would another option be to just stop using the tuple-less index in the presence of new syntax - so by example, ``` SYNTAXINDEX KWARGS d[*[]]() {} d[*[],] () {} d[**{}] () {} d[**{},] () {} d[foo=1] () {'foo': 1} d[foo=1,] () {'foo

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Chris Angelico
On Mon, Sep 28, 2020 at 3:33 PM Christopher Barker wrote: > As for using an empty tuple, thanks Guido for laying out the logic so > succinctly, and it does make it pretty simple that only the one index case is > special. Nevertheless, I think most folks expect the special case to be at > the en

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Christopher Barker
On Sun, Sep 27, 2020 at 1:51 PM David Mertz wrote: > On Sun, Sep 27, 2020 at 10:41 AM Stefano Borini > wrote: > >> I kept the tuple as the accepted option, but I am personally open to >> NoIndex as well. I am not sure how the SC would take a non-hashable, new >> constant to be >> honest, for suc

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Guido van Rossum
On Sun, Sep 27, 2020 at 4:29 AM Stefano Borini wrote: > ``` > >>> obj[**d] = "foo" # no kwd arguments provided here > ``` > I committed yesterday the following proposal > > https://github.com/python/peps/pull/1622 > > But to be honest I am not sure if we should disallow these two constructs > ``

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread MRAB
On 2020-09-27 21:47, David Mertz wrote: On Sun, Sep 27, 2020 at 10:41 AM Stefano Borini mailto:stefano.bor...@gmail.com>> wrote: I kept the tuple as the accepted option, but I am personally open to NoIndex as well. I am not sure how the SC would take a non-hashable, new constant to

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread David Mertz
On Sun, Sep 27, 2020 at 10:41 AM Stefano Borini wrote: > I kept the tuple as the accepted option, but I am personally open to > NoIndex as well. I am not sure how the SC would take a non-hashable, new > constant to be > honest, for such a specific use case. > My "vote" is for NoIndex. I suggest

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Stefano Borini
On Sun, 27 Sep 2020 at 12:28, Stefano Borini wrote: > I am not sure. I am on the fence on many topics. There seem to be no > clear solution on many of them, it boils down to taste and compromise. > In any case, I listen to all proposals (although with a small delay). > I am working on the sentinel

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Guido van Rossum
On Sat, Sep 26, 2020 at 22:57 Steven D'Aprano wrote: > Christopher, with the greatest respect, it is really demoralising for me > to explain this issue something like three, four, maybe five times now > (I'm not going to go back and count), including this thread which is > specifically about this

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Stefano Borini
On Sun, 27 Sep 2020 at 05:06, Ricky Teachey wrote: >>> obj[**d] = "foo" # no kwd arguments provided here I committed yesterday the following proposal https://github.com/python/peps/pull/1622 But to be honest I am not sure if we should disallow these two constructs d[*()] d[**{}] as equivale

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Chris Angelico
On Sun, Sep 27, 2020 at 7:08 PM Steven D'Aprano wrote: > 1. Fill in a default index with one of: > > a. None > b. empty tuple () > c. NotImplemented > d. a new, unhashable builtin Missing or NoIndex > > 1d. avoids any chance of that, but requires a new builtin; > An interesting and very good poin

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 07:12:00PM -0400, Ricky Teachey wrote: > Another inconsistency is that the case of keyword arguments only would bind > the RHS value to the first positional argument, which is the index, and not > the value. I think this is what Guido was referring to when he responded > tal

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-27 Thread Greg Ewing
On 27/09/20 7:10 pm, Steven D'Aprano wrote: kw = get_keywords() # oops, this returns an empty dict obj[**kw] = value If an explicit d[] is going to be a compile-time error, maybe anything that has the same effect at run time should be an error too? -- Greg __

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 10:43:23PM -0400, Ricky Teachey wrote: > The problem is that there is lots of existing code like this: > > def __setitem__(self, index, value): ... > > But the new features will almost certainly lead people to write new code > like this: > > d={} > obj[**d] = "foo" # no

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 03:48:42PM -0700, Christopher Barker wrote: > On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano > wrote: > >> > >> 1. We have to pass a sentinel to the setitem dunder if there is no > >> positional index passed. > > > I still don't follow this logic -- why can't nothing be

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Ricky Teachey
On Sat, Sep 26, 2020 at 11:49 PM Guido van Rossum wrote: > On Sat, Sep 26, 2020 at 7:44 PM Ricky Teachey wrote: > >> The problem is that there is lots of existing code like this: >> >> def __setitem__(self, index, value): ... >> >> But the new features will almost certainly lead people to write

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Guido van Rossum
On Sat, Sep 26, 2020 at 7:44 PM Ricky Teachey wrote: > The problem is that there is lots of existing code like this: > > def __setitem__(self, index, value): ... > > But the new features will almost certainly lead people to write new code > like this: > > d={} > obj[**d] = "foo" # no kwd argumen

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Ricky Teachey
On Sat, Sep 26, 2020, 11:30 PM Greg Ewing wrote: > On 27/09/20 3:43 pm, Ricky Teachey wrote: > > telling people "either provide a default argument for > > both index AND value in your __setitem__ method, or neither" is also a > > perfectly legitimate way forward. > > Giving the value parameter of

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Greg Ewing
On 27/09/20 3:43 pm, Ricky Teachey wrote: telling people "either provide a default argument for both index AND value in your __setitem__ method, or neither" is also a perfectly legitimate way forward. Giving the value parameter of a __setitem__ a default seems like a weird thing to do, since u

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Ricky Teachey
On Sat, Sep 26, 2020 at 10:43 PM Ricky Teachey wrote: > ...which, if someone does this arbitrarily against classes that use the > existing kind of code I gave at the first, will call (if the sentinel is () > ): > > obj.__setitem__(()) > > ...which could have all kinds of weird effects rather than

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Ricky Teachey
On Sat, Sep 26, 2020 at 10:30 PM Ben Rudiak-Gould wrote: > I don't understand the problem here. > > d[p=q] --> d.__{get,set,del}item__((), ..., p=q) > d[1, p=q] --> d.__{get,set,del}item__((1), ..., p=q) > d[1, 2, p=q] --> d.__{get,set,del}item__((1, 2), ..., p=q) > d[1, 2,

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Ben Rudiak-Gould
I don't understand the problem here. d[p=q] --> d.__{get,set,del}item__((), ..., p=q) d[1, p=q] --> d.__{get,set,del}item__((1), ..., p=q) d[1, 2, p=q] --> d.__{get,set,del}item__((1, 2), ..., p=q) d[1, 2, 3, p=q] --> d.__{get,set,del}item__((1, 2, 3), ..., p=q) d[1, 2,

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Chris Angelico
On Sun, Sep 27, 2020 at 8:49 AM Christopher Barker wrote: > > > On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano wrote: > >> > >> 1. We have to pass a sentinel to the setitem dunder if there is no > >> positional index passed. > > > I still don't follow this logic -- why can't nothing be passed?

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Ricky Teachey
Another inconsistency is that the case of keyword arguments only would bind the RHS value to the first positional argument, which is the index, and not the value. I think this is what Guido was referring to when he responded talking about introspection being required? Not sure. in any case, to me

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Christopher Barker
On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano wrote: >> >> 1. We have to pass a sentinel to the setitem dunder if there is no >> positional index passed. I still don't follow this logic -- why can't nothing be passed? The dunders either require an index or they don't, would that be just like

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Guido van Rossum
On Fri, Sep 25, 2020 at 11:26 PM Ricky Teachey wrote: > On Sat, Sep 26, 2020 at 1:51 AM Guido van Rossum wrote: > >> But this requires introspection. >> > > I'm sorry Guido I'm staring at your message and reread mine several times > and I don't understand where introspection is required. It seem

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Steven D'Aprano
On Fri, Sep 25, 2020 at 08:52:45PM -1000, David Mertz wrote: > On Fri, Sep 25, 2020, 5:49 PM Steven D'Aprano > > > Since both None and () are likely to be legitimate indexes, and > > NotImplemented is less likely to be such, I think this supports using > > NotImplemented. > > > > I think your arg

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-26 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 01:43:18AM -0400, Ricky Teachey wrote: > On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano > wrote: > > > TL;DR: > > > > 1. We have to pass a sentinel to the setitem dunder if there is no > > positional index passed. What should that sentinel be? > > > > Isn't there a prob

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-25 Thread David Mertz
On Fri, Sep 25, 2020, 5:49 PM Steven D'Aprano > Since both None and () are likely to be legitimate indexes, and > NotImplemented is less likely to be such, I think this supports using > NotImplemented. > I think your arguments for NotImplemented vs None or () are solid. But I'm having trouble cro

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-25 Thread Ricky Teachey
On Sat, Sep 26, 2020 at 1:51 AM Guido van Rossum wrote: > But this requires introspection. > I'm sorry Guido I'm staring at your message and reread mine several times and I don't understand where introspection is required. It seems like all the parser has to do is what it has always done-- pass

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-25 Thread Guido van Rossum
But this requires introspection. On Fri, Sep 25, 2020 at 22:46 Ricky Teachey wrote: > On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano > wrote: > >> TL;DR: >> >> >> >> >> >> 1. We have to pass a sentinel to the setitem dunder if there is no >> >> >> positional index passed. What should that sen

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-25 Thread Ricky Teachey
On Fri, Sep 25, 2020 at 11:50 PM Steven D'Aprano wrote: > TL;DR: > > 1. We have to pass a sentinel to the setitem dunder if there is no > positional index passed. What should that sentinel be? > Isn't there a problem with this starting assumption? Say that I have item dunder code of the signatu

[Python-ideas] Re: PEP 637 and keyword only subscripts

2020-09-25 Thread Steven D'Aprano
Change of subject line as I wish to focus on a single critical point of the PEP: keyword-only subscripts. TL;DR: 1. We have to pass a sentinel to the setitem dunder if there is no positional index passed. What should that sentinel be? * None * the empty tuple () * NotImplemented * somethi