[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Christopher Barker
I may get a chance to look carefully at this in a bit, but for now: On Tue, Sep 1, 2020 at 6:38 PM Ricky Teachey wrote: > Sorry for all the replies but I'm honestly very unsure how do this > correctly under Steven's proposal. > That's OK. It's going to be tricky, and keeping backward

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Random832
On Tue, Sep 1, 2020, at 21:06, Ricky Teachey wrote: > Here's my attempt, it is probably lacking. I'm five years into a > self-taught venture in python... If I can't get this right the first > time, it worries me a little. > > > MISSING=object() > > def __getitem__(self, key=MISSING,

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Brendan Barnwell
On 2020-09-01 07:24, Steven D'Aprano wrote: Operator overloading is a thing, so if you want `a + b` to mean looking up a database for `a` and writing it to file `b`, you can. But the blessed use-cases for the `+` operator are numeric addition and sequence concatenation. Anything else is an

[Python-ideas] Re: On blessed abuse of operators [was: Changing item dunder ...]

2020-09-01 Thread Greg Ewing
On 2/09/20 8:35 am, Chris Angelico wrote: Maybe we need a different term for this kind of overloading, where we're not even TRYING to follow the normal semantics for that operation, but are just doing something because it "feels right". Operator repurposing? -- Greg

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Greg Ewing
On 2/09/20 5:14 am, Stephan Hoyer wrote: On Tue, Sep 1, 2020 at 9:59 AM David Mertz I think we need this for the same reason why we need **kwargs in normal function calls: it makes it possible to forward dictionaries of arguments to another method. If we don't have dict unpacking, you'd have

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Ricky Teachey
On Tue, Sep 1, 2020, 9:20 PM Ricky Teachey wrote: > On Tue, Sep 1, 2020, 9:06 PM Ricky Teachey wrote: > >> On Tue, Sep 1, 2020, 8:35 PM Guido van Rossum wrote: >> >>> On Tue, Sep 1, 2020 at 4:57 PM Greg Ewing >>> wrote: >>> On 2/09/20 2:24 am, Steven D'Aprano wrote: > On Sun, Aug

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Ricky Teachey
On Tue, Sep 1, 2020, 9:06 PM Ricky Teachey wrote: > On Tue, Sep 1, 2020, 8:35 PM Guido van Rossum wrote: > >> On Tue, Sep 1, 2020 at 4:57 PM Greg Ewing >> wrote: >> >>> On 2/09/20 2:24 am, Steven D'Aprano wrote: >>> > On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: >>> >> On

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Ricky Teachey
On Tue, Sep 1, 2020, 8:35 PM Guido van Rossum wrote: > On Tue, Sep 1, 2020 at 4:57 PM Greg Ewing > wrote: > >> On 2/09/20 2:24 am, Steven D'Aprano wrote: >> > On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: >> >> On 30/08/20 3:06 pm, Steven D'Aprano wrote: >> >>> On Thu, Aug 27,

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Greg Ewing
On 2/09/20 3:44 am, Steven D'Aprano wrote: (9) Keyword-only subscripts are permitted: obj[spam=1, eggs=2] # calls type(obj).__getitem__(spam=1, eggs=2) del obj[spam=1, eggs=2] # calls type(obj).__delitem__(spam=1, eggs=2) An alternative is to pass an empty tuple as the

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Guido van Rossum
On Tue, Sep 1, 2020 at 4:57 PM Greg Ewing wrote: > On 2/09/20 2:24 am, Steven D'Aprano wrote: > > On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: > >> On 30/08/20 3:06 pm, Steven D'Aprano wrote: > >>> On Thu, Aug 27, 2020 at 11:13:38PM +1200, Greg Ewing wrote: > >>> > a[17,

[Python-ideas] Re: PEP-0472 revisited - draft

2020-09-01 Thread Greg Ewing
On 2/09/20 3:20 am, Christopher Barker wrote: I think that type hints are used in specific places, and thus the interpreter could know if a given [] was a type hint or an indexing operation, and thus could dispatch it differently. I don't think so. We need to be able to do things like

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Greg Ewing
On 2/09/20 2:24 am, Steven D'Aprano wrote: On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: On 30/08/20 3:06 pm, Steven D'Aprano wrote: On Thu, Aug 27, 2020 at 11:13:38PM +1200, Greg Ewing wrote: a[17, 42] a[time = 17, money = 42] a[money = 42, time = 17] > Compares

[Python-ideas] Re: On blessed abuse of operators [was: Changing item dunder ...]

2020-09-01 Thread Chris Angelico
On Wed, Sep 2, 2020 at 3:48 AM Stephen J. Turnbull wrote: > > A digression on abuse of operators, notation, and "abuse of notation". > > Steven D'Aprano writes: > > On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: > > > > I don't see why we need to pick one use case to bless as the >

[Python-ideas] Re: PEP-0472 revisited - draft

2020-09-01 Thread Christopher Barker
On Tue, Sep 1, 2020 at 9:51 AM Guido van Rossum wrote: > On Tue, Sep 1, 2020 at 8:20 AM Christopher Barker > wrote: > >> Question: it strikes me that the use case of [] for type hints is >> logically quite different than for indexing. So do they need to use the >> same syntax / dunder? >> >> I

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Christopher Barker
very related to this conversation -- isn't the use of [] for indexing and its use in Type hinting functionally very different as well? -CHB On Tue, Sep 1, 2020 at 9:55 AM David Mertz wrote: > > On 30/08/20 3:06 pm, Steven D'Aprano wrote: > >> (There are a few gray areas, such as

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Dominik Vilsmeier
On 01.09.20 17:44, Steven D'Aprano wrote: (9) Keyword-only subscripts are permitted: obj[spam=1, eggs=2] # calls type(obj).__getitem__(spam=1, eggs=2) del obj[spam=1, eggs=2] # calls type(obj).__delitem__(spam=1, eggs=2) but note that the setter is awkward since the

[Python-ideas] On blessed abuse of operators [was: Changing item dunder ...]

2020-09-01 Thread Stephen J. Turnbull
A digression on abuse of operators, notation, and "abuse of notation". Steven D'Aprano writes: > On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: > > I don't see why we need to pick one use case to bless as the > > official "true" use case. > > We do that for every other

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Stephan Hoyer
On Tue, Sep 1, 2020 at 9:59 AM David Mertz wrote: > On Tue, Sep 1, 2020 at 11:45 AM Steven D'Aprano > wrote: > >> (8) Dict unpacking is permitted: >> >> items = {'spam': 1, 'eggs': 2} >> obj[index, **items] >> # equivalent to obj[index, spam=1, eggs=2] >> > > I would prefer to

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread David Mertz
Thank you Steven, This exactly matches what my goal would be, except the below. On Tue, Sep 1, 2020 at 11:45 AM Steven D'Aprano wrote: > (8) Dict unpacking is permitted: > > items = {'spam': 1, 'eggs': 2} > obj[index, **items] > # equivalent to obj[index, spam=1, eggs=2] > I would

[Python-ideas] Re: PEP-0472 revisited - draft

2020-09-01 Thread Guido van Rossum
On Tue, Sep 1, 2020 at 8:20 AM Christopher Barker wrote: > Thanks -- good to get this written down! > > Question: it strikes me that the use case of [] for type hints is > logically quite different than for indexing. So do they need to use the > same syntax / dunder? > > I think that type hints

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread David Mertz
> On 30/08/20 3:06 pm, Steven D'Aprano wrote: > (There are a few gray areas, such as array/matrix/vector addition, which > sneak into the "acceptable" area by virtue of their long usage in > mathematics.) > >>> a / b/ c 0.01 >>> home / 'git' / 'pip'

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Guido van Rossum
On Tue, Sep 1, 2020 at 8:45 AM Steven D'Aprano wrote: > This is slightly revised version of something I sent to Stefano two > weeks ago. I hope he is planning to use this, or something similar, in > the PEP, but for what it's worth here it is for discussion. > Excellent. Could you add some

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Guido van Rossum
On Tue, Sep 1, 2020 at 9:34 AM Jonathan Fine wrote: > Hi Steven > > Thank you, for reviewing and combining your previous statements into a > single message. This is a great help, for the creation and editing of the > revised PEP. > > I intend to do something similar myself. Perhaps others might

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Jonathan Fine
Hi Steven Thank you, for reviewing and combining your previous statements into a single message. This is a great help, for the creation and editing of the revised PEP. I intend to do something similar myself. Perhaps others might also want to do something similar. -- Jonathan

[Python-ideas] Re: PEP-0472 revisited - draft

2020-09-01 Thread Ricky Teachey
On Tue, Sep 1, 2020 at 11:21 AM Christopher Barker wrote: > Thanks -- good to get this written down! > > Question: it strikes me that the use case of [] for type hints is > logically quite different than for indexing. So do they need to use the > same syntax / dunder? > How would we

[Python-ideas] Re: Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Christopher Barker
Thanks Steve, it's good to see this so clearly laid out. And indeed, v=fior backward compatibility, while also being as similar to function call behavior as possible, this is pretty much the only option. One request: # Comma-separated indices with keywords: > > obj[foo, bar, spam=1,

[Python-ideas] Proposed new syntax for subscripting (was PEP 472)

2020-09-01 Thread Steven D'Aprano
This is slightly revised version of something I sent to Stefano two weeks ago. I hope he is planning to use this, or something similar, in the PEP, but for what it's worth here it is for discussion. This is, as far as I can tell, the minimum language change needed to support keywords in

[Python-ideas] Re: PEP-0472 revisited - draft

2020-09-01 Thread Christopher Barker
Thanks -- good to get this written down! Question: it strikes me that the use case of [] for type hints is logically quite different than for indexing. So do they need to use the same syntax / dunder? I think that type hints are used in specific places, and thus the interpreter could know if a

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Steven D'Aprano
On Sun, Aug 30, 2020 at 05:49:50PM +1200, Greg Ewing wrote: > On 30/08/20 3:06 pm, Steven D'Aprano wrote: > >On Thu, Aug 27, 2020 at 11:13:38PM +1200, Greg Ewing wrote: > > > >>a[17, 42] > >>a[time = 17, money = 42] > >>a[money = 42, time = 17] > > > >I don't think that something like

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-09-01 Thread Ricky Teachey
On Sun, Aug 30, 2020 at 6:19 PM Stefano Borini wrote: > 2. pandas has this exact problem with column names, and while they > have a workaround, in my opinion it is suboptimal > What is the workaround? --- Ricky. "I've never met a Kentucky man who wasn't

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-09-01 Thread Inada Naoki
On Mon, Aug 31, 2020 at 9:30 PM wrote: > I have a use case which relates to this request: iterating over a dict > starting from a given key. I would like to achieve this without having to pay > the full O(n) cost if I'm going to be iterating over only a few items. My > understanding is that

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-09-01 Thread Dominik Vilsmeier
On 01.09.20 11:22, Zig Zigson wrote: I believe I described my case poorly, the process to get from one state (key) to the next is an external (slow) process; the value stored is not the next state but a value calculated while advancing the state. This dict serves as a way to quickly skip

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-09-01 Thread Zig Zigson
I believe I described my case poorly, the process to get from one state (key) to the next is an external (slow) process; the value stored is not the next state but a value calculated while advancing the state. This dict serves as a way to quickly skip steps of the external process when it has

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-09-01 Thread Zig Zigson
Having gotten to an implementation, you are correct, the dict iteration does not take the lion's share, or at least there are several other steps in my application which dwarf the dict traversal operations in any case. I don't think I in practice have a compelling case here, so all I'm left with

[Python-ideas] Re: Access (ordered) dict by index; insert slice

2020-09-01 Thread Dominik Vilsmeier
On 31.08.20 06:01, junkneno...@gmail.com wrote: I have a use case which relates to this request: iterating over a dict starting from a given key. I would like to achieve this without having to pay the full O(n) cost if I'm going to be iterating over only a few items. My understanding is that

[Python-ideas] PEP-0472 revisited - draft

2020-09-01 Thread Stefano Borini
For those interested in the new draft of ex PEP-0472 (which has joined the choir invisible), I opened a draft PR https://github.com/python/peps/pull/1579 This first draft contains only the revisited motivation and background. I'll add the technical decisions etc in the upcoming nights. --