[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 10:43:01PM +0100, Nicholas Cole wrote: > I don't find such examples a conclusive argument in favour of this > syntax at all. I wouldn't expect you would -- Stefano made it up as an example of something that he felt was a poor use of subscripts! You should not 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

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 01:47:56PM -0300, Sebastian Kreft wrote: > In this fashion have you considering having keyword only indices, that is > to only allow either obj[1, 2] or obj[row=1, col=2] (if the class supports > it), and disallow mixing positional and keyword indices, meaning obj[1, >

[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

[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

[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

[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: Suggestion: annotated exceptions

2020-09-26 Thread Steven D'Aprano
On Sat, Sep 26, 2020 at 09:59:27AM +0200, Sascha Schlemmer via Python-ideas wrote: > I think a clear distinction has to be made between errors that belong > to the api surface of a function e.g. some `ValueError` or > `ZeroDivisionError` and *exceptional* errors e,g.`KeyboardInterrupt` > or

[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,

[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 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread David Mertz
On Sat, Sep 26, 2020 at 11:45 AM Nicholas Cole wrote: > > I think this is a very natural looking use case, and is not as well > addressed by putting the multiplier outside the indexing. Imagine you have > two arrays that store lengths, but not necessarily in the same units. > Whatever the

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread Guido van Rossum
On Sat, Sep 26, 2020 at 2:44 PM Nicholas Cole wrote: > I can't help feeling that this is a syntax looking for a set of > solutions to apply itself to. It will add enormous complexity > (together, no doubt, with speed issues and backwards-compatibility > issues) to the language, and I'm not sure

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread Nicholas Cole
On Sat, Sep 26, 2020 at 9:35 PM David Mertz wrote: > > On Sat, Sep 26, 2020 at 12:50 AM Stefano Borini > wrote: >> >> Other use cases are certainly allowed, but to me, something like >> >> a[1, 2, unit="meters"] >> a[1, 2, unit="meters"] = 3 >> >> makes me feel uncomfortable, although I might

[Python-ideas] Re: Suggestion: annotated exceptions

2020-09-26 Thread Chris Angelico
On Sat, Sep 26, 2020 at 10:47 PM Sascha Schlemmer via Python-ideas wrote: > ``` > def div(a: int, b: int) -> Result[float, ZeroDivisionError]: > try: > return Success(a / b) > except ZeroDivisionError as error: > return Failure(error) > ``` > > Now `div` does return a valid

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread David Mertz
On Sat, Sep 26, 2020 at 12:50 AM Stefano Borini wrote: > Other use cases are certainly allowed, but to me, something like > > a[1, 2, unit="meters"] > a[1, 2, unit="meters"] = 3 makes me feel uncomfortable, although I might learn to accept it. Then why isn't the unit close to 3, as in > >

[Python-ideas] Re: Trash bin

2020-09-26 Thread Eric V. Smith
On 9/25/2020 1:34 PM, Paul Bryan wrote: On Fri, 2020-09-25 at 18:19 +0200, Marco Sulla wrote: That I hope it's not the place where this proposal will be sent. My idea is apparently simple: what if, anytime we create an object, instead of deleting it, we send it in a trash bin? If the object

[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

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread Sebastian Kreft
On Sat, Sep 26, 2020 at 7:51 AM Stefano Borini wrote: > On Sat, 26 Sep 2020 at 04:02, Steven D'Aprano wrote: > > > Did you just completely undermine the rationale for your own PEP? > > > > Isn't the entire purpose of this PEP to allow subscripts to include > > keyword arguments? And now you are

[Python-ideas] Re: Suggestion: annotated exceptions

2020-09-26 Thread Wes Turner
On Sat, Sep 26, 2020 at 8:50 AM Sascha Schlemmer via Python-ideas < python-ideas@python.org> wrote: > I think a clear distinction has to be made between errors that belong to > the api surface of a function e.g. some `ValueError` or `ZeroDivisionError` > and *exceptional* errors

[Python-ideas] Re: Suggestion: annotated exceptions

2020-09-26 Thread Stephen J. Turnbull
On Fri, Sep 25, 2020 at 3:38 PM Steven D'Aprano wrote: > The last thing I want to see is people being encouraged to write code > like this: > > def demo(arg)->Something: [... elided ...] > except: > # Any other unexpected error. > raise

[Python-ideas] Re: Suggestion: annotated exceptions

2020-09-26 Thread Sascha Schlemmer via Python-ideas
I think a clear distinction has to be made between errors that belong to the api surface of a function e.g. some `ValueError` or `ZeroDivisionError` and *exceptional* errors e,g.`KeyboardInterrupt` or `DatabaseExplodedError`. For the latter case exceptions work perfectly well as they are and it

[Python-ideas] Re: PEP 637 - support for indexing with keyword arguments (Was: Re: PEP 9999 (provisional): ...)

2020-09-26 Thread Stefano Borini
On Sat, 26 Sep 2020 at 04:02, Steven D'Aprano wrote: > Did you just completely undermine the rationale for your own PEP? > > Isn't the entire purpose of this PEP to allow subscripts to include > keyword arguments? And now you are describing it as "poor design"? Not really. to _me_, an indexing

[Python-ideas] Re: PEP 9999 (provisional): support for indexing with keyword arguments

2020-09-26 Thread Stefano Borini
On Sat, 26 Sep 2020 at 05:10, Steven D'Aprano wrote: > > I recommend that the PEP be changed to allow `*args` inside subscripts. Will do. -- Kind regards, Stefano Borini ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send

[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

[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

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

2020-09-26 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

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

2020-09-26 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