[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Jonathan Fine
Guido wrote: > I think it’s a reasonable idea and encourage you to start working on a > design for the API and then a PRP. > In this post, I explore how the new API might interact with dict objects. (I think PRP is a typo for PEP.) Here is an example of the present behaviour >>> d = dict()

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Steven D'Aprano
On Fri, Jul 17, 2020 at 11:14:21AM +0100, Jonathan Fine wrote: > So what should be the new behaviour of: > >>> d = dict() > >>> d[x=1, y=2] = 3 TypeError: dict subscripting takes no keyword arguments Just because something is syntactically allowed doesn't mean it has to be given a mean

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Jonathan Fine
Steve and I have different opinions, as to what the new behaviour of: >>> d = dict() >>> d[x=1, y=2] = 3 should be. He prefers that the assignment fail with TypeError: dict subscripting takes no keyword arguments I prefer that the assignment succeed (and hence a new key-value pair is

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Ricky Teachey
On Fri, Jul 17, 2020, 6:17 AM Jonathan Fine wrote: > Guido wrote: > >> I think it’s a reasonable idea and encourage you to start working on a >> design for the API and then a PRP. >> > > In this post, I explore how the new API might interact with dict objects. > (I think PRP is a typo for PEP.) >

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread David Mertz
On Fri, Jul 17, 2020, 8:16 AM Jonathan Fine wrote: > Steve and I have different opinions, as to what the new behaviour of: > >>> d = dict() > >>> d[x=1, y=2] = 3 > should be. > > He prefers that the assignment fail with > TypeError: dict subscripting takes no keyword arguments > > I p

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread David Mertz
Fwiw, I'm probably -0 on the feature itself. Someone suggested it could be useful for xarray, but I'm not sure now what that would look like. If someone had an example, I could easily be moved. I'm not against the original suggested use with type annotations, but I also don't really care about it.

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Christopher Barker
On Fri, Jul 17, 2020 at 9:20 AM David Mertz wrote: > Fwiw, I'm probably -0 on the feature itself. Someone suggested it could be > useful for xarray, but I'm not sure now what that would look like. If > someone had an example, I could easily be moved. > agreed -- I can imagine the use case, but a

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Ricky Teachey
On Fri, Jul 17, 2020 at 12:30 PM Christopher Barker wrote: > On Fri, Jul 17, 2020 at 9:20 AM David Mertz wrote: > >> Fwiw, I'm probably -0 on the feature itself. Someone suggested it could >> be useful for xarray, but I'm not sure now what that would look like. If >> someone had an example, I co

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Jonathan Fine
Thank you all, for your useful contributions. I particularly value the insight you've given me regarding the experience that underlies your views. I'll respond to your comments tomorrow. I am able today to respond to one question. Ricky asked if >>> key_object = K(a=1, b=2) # where K is some n

[Python-ideas] Re: Thoughts about Fast Python Engine and Python EveryWhere

2020-07-17 Thread Brett Cannon
On Thu, Jul 16, 2020 at 11:52 AM wrote: > CPython is portable but due to integrated standard library (builtin > functionality) it is hard to evolve it, How so? The stdlib is just a collection of packages we happen to ship with Python. Think of it as if we ship blessed packages from PyPI with Py

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Christopher Barker
On Fri, Jul 17, 2020 at 11:49 AM Jonathan Fine wrote: > I am able today to respond to one question. Ricky asked if >>>> key_object = K(a=1, b=2) # where K is some new key object type >>>> d1 = {key_object: 3} >>>> d2 = {} >>>> d2[a=1, b=2] = 3 >>>> assert d1==d2 > was what I

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Todd
On Fri, Jul 17, 2020, 12:10 David Mertz wrote: > On Fri, Jul 17, 2020, 8:16 AM Jonathan Fine wrote: > >> Steve and I have different opinions, as to what the new behaviour of: >> >>> d = dict() >> >>> d[x=1, y=2] = 3 >> should be. >> >> He prefers that the assignment fail with >> Type

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Todd
On Fri, Jul 17, 2020 at 12:19 PM David Mertz wrote: > Fwiw, I'm probably -0 on the feature itself. Someone suggested it could be > useful for xarray, but I'm not sure now what that would look like. If > someone had an example, I could easily be moved. > Here is what it currently looks like to as

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread David Mertz via Python-ideas
On Fri, Jul 17, 2020 at 4:12 PM Todd wrote: > ds["empty"][lon=1:5, lat=6:] = 10 > I agree that looks really nice. I think this is the first suggestion to allow slices on the RHS of keyword indexing. That's the part that was missing in me understanding how this would help xarray greatly. It's als

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Rhodri James
On 17/07/2020 21:11, Todd wrote: On Fri, Jul 17, 2020 at 12:19 PM David Mertz wrote: Fwiw, I'm probably -0 on the feature itself. Someone suggested it could be useful for xarray, but I'm not sure now what that would look like. If someone had an example, I could easily be moved. Here is what

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Andras Tantos
Jonathan and all! Thanks for picking up on this thread, I almost given up hope that anyone would be interested. Then it suddenly blew up :)! Jonathan, your suggestion makes sense as a stop-gap measure for current Python, but I'm unclear on the way forward to the new syntax: When you say we

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Steven D'Aprano
On Fri, Jul 17, 2020 at 11:11:17AM -0400, Ricky Teachey wrote: > It seems to me that the validity of this key-object paradigm is directly > tied to the decision of whether or not to change the get/set item dunder > signatures. But note that even if we allow keyword args in subscripts, we still d

[Python-ideas] Re: PEP 472 -- Support for indexing with keyword arguments

2020-07-17 Thread Ricky Teachey
On Fri, Jul 17, 2020 at 7:21 PM Steven D'Aprano wrote: > On Fri, Jul 17, 2020 at 11:11:17AM -0400, Ricky Teachey wrote: > > ... > > For backwards-compatibility, there will only ever be a single positional > argument passed into the method. That's because comma-separated values > in a subscript ar