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

2021-03-10 Thread henryfs
By the way, a second problem with __getitem__ and __setitem__ is they are really messy to type (and this likely would make it worse). If, however, there was a new __getindex__ and __setindex__ with normal Python *args and **kwargs symantics, that would be really easy to type. For example, when

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

2020-10-07 Thread Stefano Borini
On Wed, 7 Oct 2020 at 11:39, Steven D'Aprano wrote: > One possible advantage is that with axis='row', I don't have to > worry about, or test for, mutually exclusive keywords: > > matrix[row=2, col=3] > # can't get both a row and a column at the same time Well, they are not mutually

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

2020-10-07 Thread Steven D'Aprano
On Wed, Sep 30, 2020 at 11:03:28AM -0300, Sebastian Kreft wrote: > Have you considered using matrix[row=3], matrix[col=3]? In that case it > would be a keyword only access. What advantages do you see with your > current API? Yes I have considered it. One possible advantage is that with

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

2020-09-30 Thread Henry F. Schreiner
I know, I was just referring to making this a standard python function with *args, **kwargs. This PEP only solves one specific problem (keyword arguments), while it seems like it would be worth while solving all of them (no arguments, tuple vs. list, and having to learn a special one-off syntax

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

2020-09-30 Thread Sebastian Kreft
On Wed, Sep 30, 2020 at 2:44 AM Steven D'Aprano wrote: > On Sun, Sep 27, 2020 at 07:59:18AM -0300, Sebastian Kreft wrote: > > > Hi Steven, could you share some examples of what you have in mind. > Having a > > more concrete example of an API that would benefit from > mixed-subscripting > > would

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

2020-09-30 Thread Stefano Borini
On Tue, 29 Sep 2020 at 22:31, wrote: > Furthermore, you currently can't tell the difference between `x[(a, b)]` and > `x[a, b]`; with the new function, libraries could differentiate, and maybe > eventually make them behave reasonably (you can always use x[*c] if you > already have a tuple,

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

2020-09-30 Thread Stefano Borini
On Wed, 30 Sep 2020 at 06:44, Steven D'Aprano wrote: > matrix[3, 4] # unambiguously a cell reference > matrix[3] # ambiguous, forbidden > matrix[3, axis='row'] # unambiguously a row > matrix[3, axis='col'] # unambiguously a column I guess everybody

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

2020-09-29 Thread Steven D'Aprano
On Sun, Sep 27, 2020 at 07:59:18AM -0300, Sebastian Kreft wrote: > Hi Steven, could you share some examples of what you have in mind. Having a > more concrete example of an API that would benefit from mixed-subscripting > would allow us to better understand its usefulness. I have an experimental

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

2020-09-29 Thread David Mertz
On Tue, Sep 29, 2020, 2:41 PM Sebastian Kreft > You mean that internally_inches means the stored values are in inches, and > that by specifying a unit, you will scale up all the passed values? > > So that, internally_inches[4:6, 8:10, unit="meters"] = [[4, 2], [1, 3]] > would save in the (4:6,

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

2020-09-29 Thread Chris Angelico
On Wed, Sep 30, 2020 at 10:41 AM Sebastian Kreft wrote: > If I understood correctly what's going on, what would the difference between > > del internally_inches[4:6, 8:10, unit="meters"] and del > internally_inches[4:6, 8:10, unit="inches"] > Probably nothing, which shows that the ability to

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

2020-09-29 Thread Sebastian Kreft
On Tue, Sep 29, 2020 at 7:27 PM David Mertz wrote: > On Tue, Sep 29, 2020 at 12:09 PM Sebastian Kreft wrote: > >> On Tue, Sep 29, 2020 at 6:56 PM David Mertz wrote: >> >>> I still think it would improve the PEP significantly if it added one >>> case of mixed positional/keyword indexing. Lots

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

2020-09-29 Thread David Mertz
On Tue, Sep 29, 2020 at 12:09 PM Sebastian Kreft wrote: > On Tue, Sep 29, 2020 at 6:56 PM David Mertz wrote: > >> I still think it would improve the PEP significantly if it added one case >> of mixed positional/keyword indexing. Lots of suggestions have floated by, >> and I don't care which

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

2020-09-29 Thread Sebastian Kreft
On Tue, Sep 29, 2020 at 6:56 PM David Mertz wrote: > I still think it would improve the PEP significantly if it added one case > of mixed positional/keyword indexing. Lots of suggestions have floated by, > and I don't care which one is used, but something to demonstrate that > within the PEP. >

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

2020-09-29 Thread David Mertz
I still think it would improve the PEP significantly if it added one case of mixed positional/keyword indexing. Lots of suggestions have floated by, and I don't care which one is used, but something to demonstrate that within the PEP. On Tue, Sep 29, 2020 at 11:43 AM Guido van Rossum wrote: >

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

2020-09-29 Thread Guido van Rossum
At this point I think we're all set for use cases, both for keyword-only and for mixed use. Clearly a lot of libraries are going to be able to provide better APIs using this PEP, and mixed use of positionals and keywords will be quite useful to some of these. -- --Guido van Rossum

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

2020-09-29 Thread henryfs
> Do you have an example from boost-histogram.. One of the dev's here, and actually, I think "Hist" would use it, rather than boost-histogram directly. In boost-histogram, axis are only represented by numbers, so `h[{0:slice(2,5)}]` probably could not be written `h[0=2:5]` even after this PEP;

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

2020-09-28 Thread Christopher Barker
Sorry if this isn't the right thread -- there's a few now. But for an example of using both positional and keyword index parameters: I maintain a library (gridded) that provides an abstraction over data on various types of grid (in this case generally Oceanographic model output) -- they can be

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

2020-09-27 Thread Stephan Hoyer
On Sat, Sep 26, 2020 at 8:40 PM Steven D'Aprano wrote: > 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

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

2020-09-27 Thread Stefano Borini
On Sun, 27 Sep 2020 at 06:27, Steven D'Aprano wrote: > As far as speed and complexity goes, I do not understand the C > implementation well enough to categorically dismiss your claims, but > from everything I have seen, neither is true: this should not have any > significant slowdown, and the

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

2020-09-27 Thread Sebastian Kreft
On Sun, Sep 27, 2020 at 12:43 AM Steven D'Aprano wrote: > 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

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

2020-09-25 Thread Ben Rudiak-Gould
On Fri, Sep 25, 2020 at 8:26 PM David Mertz wrote: > E.g. we would have: > > newthing[(), foo=1, bar=4:5] == newthing[foo=1, bar=4:5] > Right, but we also have newthing[(2, 3), foo=1, bar=4:5] == newthing[2, 3, foo=1, bar=4:5] which seems exactly analogous. A disambiguation scheme

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

2020-09-25 Thread David Mertz
On Fri, Sep 25, 2020 at 4:36 PM Steven D'Aprano wrote: > > I.e. consider: > > >>> d = dict() > > >>> d[()] = "foo" > > >>> d > > {(): 'foo'} > > I agree with Ricky that the choice of empty tuple should be justified > better by the PEP, and alternatives (None, NotImplemented) discussed. > But I

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

2020-09-25 Thread Steven D'Aprano
On Fri, Sep 25, 2020 at 09:53:41PM +0100, Stefano Borini wrote: > On Fri, 25 Sep 2020 at 05:55, David Mertz wrote: > > Smuggling in a generic function calls in square brackets is > > undesirable (but obviously not preventable at a language level). > > However, I feel like keywords might very

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

2020-09-25 Thread Steven D'Aprano
On Fri, Sep 25, 2020 at 05:05:52PM -0400, Ricky Teachey wrote: > * sheepishly, whispering mostly to myself * > > All of that could be solved with new dunders. What would be the signature of the new dunders? How will the new dunders be backwards compatible? Previous discussions on this

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

2020-09-25 Thread Steven D'Aprano
Quoting levels are a bit messed up in David's post, I've tried to fix them bu apologies if I'm attributing words to David that he didn't write. On Thu, Sep 24, 2020 at 07:04:31PM -1000, David Mertz wrote: > Is this a breaking change? It feels borderline. > > > Keyword-only subscripts are

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

2020-09-25 Thread Stefano Borini
Ricky, I'd love new dunders too but it would explode in complexity. The likelihood of being approved is pretty much non-existent as far as I understand. If you want, we can write together a competing PEP with that solution, so that the Steering Council can have two ideas. I would not mind

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

2020-09-25 Thread Ricky Teachey
On Fri, Sep 25, 2020 at 4:57 PM Stefano Borini wrote: > On Fri, 25 Sep 2020 at 14:07, Ricky Teachey wrote: > > > > I'd like to hear more about why the empty tuple has been selected as the > default index. > > It's still not settled. Steven proposed None, I propose empty tuple > for affinity

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

2020-09-25 Thread Stefano Borini
On Fri, 25 Sep 2020 at 14:07, Ricky Teachey wrote: > > I'd like to hear more about why the empty tuple has been selected as the > default index. It's still not settled. Steven proposed None, I propose empty tuple for affinity with *args behavior, others proposed no positional arg at all, but

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

2020-09-25 Thread Stefano Borini
On Fri, 25 Sep 2020 at 05:55, David Mertz wrote: > Smuggling in a generic function calls in square brackets is undesirable (but > obviously not preventable at a language level). However, I feel like > keywords might very often "alter the behavior." > > For example, imagine we have a

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

2020-09-25 Thread Christopher Barker
On Fri, Sep 25, 2020 at 1:36 PM MRAB wrote: > It currently doesn't support multiple indexes, so there's no distinction > between one index that's a 2-tuple and 2 indexes: d[(1, 2)] == d[1, 2]. > yeah, but one index isn't in a 1-tuple (much discussed on this thread), so now we have the someone

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

2020-09-25 Thread MRAB
On 2020-09-25 20:36, Christopher Barker wrote: On Fri, Sep 25, 2020 at 6:05 AM Ricky Teachey > wrote: I'd like to hear more about why the empty tuple has been selected as the default index. It makes sense to me: if more than one index is passed, they are

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

2020-09-25 Thread Ricky Teachey
On Fri, Sep 25, 2020 at 3:36 PM Christopher Barker wrote: > On Fri, Sep 25, 2020 at 6:05 AM Ricky Teachey wrote: > >> I'd like to hear more about why the empty tuple has been selected as the >> default index. >> > > It makes sense to me: if more than one index is passed, they are passed as > a

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

2020-09-25 Thread Christopher Barker
On Fri, Sep 25, 2020 at 6:05 AM Ricky Teachey wrote: > I'd like to hear more about why the empty tuple has been selected as the > default index. > It makes sense to me: if more than one index is passed, they are passed as a tuple. so many classes need to handle tuples anyway. What other

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

2020-09-25 Thread Stefano Borini
On Thu, 24 Sep 2020 at 22:22, Guido van Rossum wrote: > - I recommend that you carefully look over the PEP as rendered on python.org > (link above) and try to fix any markup oddities. E.g. some comments are > line-wrapped, which looks ugly, and some bulleted lists have an extra blank > line

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

2020-09-25 Thread Ricky Teachey
I'd like to hear more about why the empty tuple has been selected as the default index. On Fri, Sep 25, 2020, 1:07 AM David Mertz wrote: > Is this a breaking change? It feels borderline. > > Keyword-only subscripts are permitted. The positional index will be the >> empty tuple: >> obj[spam=1,

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

2020-09-24 Thread David Mertz
Is this a breaking change? It feels borderline. Keyword-only subscripts are permitted. The positional index will be the > empty tuple: > obj[spam=1, eggs=2] > # calls type(obj).__getitem__(obj, (), spam=1, eggs=2) I.e. consider: >>> d = dict() >>> d[()] = "foo" >>> d {(): 'foo'} I don't

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

2020-09-24 Thread David Mertz
I feel like this paragraph in the PEP goes a little bit too far, but I understand its good intention. The first difference is in meaning to the reader. A function call says > "arbitrary function call potentially with side-effects". An indexing > operation says "lookup", typically to point at a

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

2020-09-24 Thread Steven D'Aprano
On Thu, Sep 24, 2020 at 07:32:37PM -, henr...@princeton.edu wrote: > Where is the discussion on this PEP going to be? In this thread, or a > new thread? I see no reason why we cannot continue discussion in this thread. > Sorry for not having followed these closely enough to know. I'd like

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

2020-09-24 Thread Guido van Rossum
https://www.python.org/dev/peps/pep-0637/ Thank you Stefano and Jonathan for a very carefully written and thought-out PEP. I trust that the background etc. are representing past discussion, so I am going to focus on the spec itself. Fortunately I only have a few nits, really. (If you submit new

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

2020-09-24 Thread Christopher Barker
not sure where further discussion will be, but absolutely look at the length discussion already on this list, where your question has been much discussed. -CHB On Thu, Sep 24, 2020 at 1:01 PM wrote: > Where is the discussion on this PEP going to be? In this thread, or a new > thread? Sorry

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

2020-09-24 Thread henryfs
Where is the discussion on this PEP going to be? In this thread, or a new thread? Sorry for not having followed these closely enough to know. I'd like to point out that boost-histogram and xarray (at least) would love this as well, as we both (independently) came up with dict-in-index

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

2020-09-23 Thread Todd
It is working for me now. On Wed, Sep 23, 2020, 17:33 Ricky Teachey wrote: > Hmmm, getting a 404 at: > > https://www.python.org/dev/peps/pep-0637 > > Is this just a temporary condition or a bug? > > --- > Ricky. > > "I've never met a Kentucky man who wasn't either thinking about going home > or

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

2020-09-23 Thread Chris Angelico
On Thu, Sep 24, 2020 at 7:33 AM Ricky Teachey wrote: > > Hmmm, getting a 404 at: > > https://www.python.org/dev/peps/pep-0637 > > Is this just a temporary condition or a bug? > Everything seems to be happy, so I'm going to guess that it's just taking a bit of time to propagate out. Give it a few

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

2020-09-23 Thread Ricky Teachey
Hmmm, getting a 404 at: https://www.python.org/dev/peps/pep-0637 Is this just a temporary condition or a bug? --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Wed, Sep 23, 2020 at 4:56 PM Stefano Borini wrote: