[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Rhodri James
On 04/10/2019 20:34, Caleb Donovick wrote: While there is no restriction on passing dicts to getitem. Doing so tends to be a bit ugly. I have two main use cases in mind for this syntax. The first and perhaps the most obvious, is doing relational queries. ``` where_x_1 = db[x=1] ``` is more be

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Random832
On Mon, Oct 7, 2019, at 09:22, Rhodri James wrote: > On 04/10/2019 20:34, Caleb Donovick wrote: > > The first and perhaps the most obvious, is doing relational queries. > > ``` > > where_x_1 = db[x=1] > > ``` > > is more beautiful than > > ``` > > where_x_1 = db[dict(x=1)] > > where_x_1 = db[{'x':

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Random832
On Mon, Oct 7, 2019, at 09:22, Rhodri James wrote: > > Allowing key value pairs in geitem need not change the interface of > > getitem. All the key value pairs could be collected as a dict and passed > > to getitem as the index. > > Um. Stop me if I'm wrong, but isn't that exactly a change to t

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Joao S. O. Bueno
So, in short, your idea is to allow "=" signs inside `[]` get notation to be translated to dicts on the call, in the same way comma separated values are translated to tuples? I see no backwards syntax incompatibility in that, and the tuple-translation is indeed quite a helper in many cases. The us

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Rhodri James
On 07/10/2019 14:56, Random832 wrote: On Mon, Oct 7, 2019, at 09:22, Rhodri James wrote: Allowing key value pairs in geitem need not change the interface of getitem. All the key value pairs could be collected as a dict and passed to getitem as the index. Um. Stop me if I'm wrong, but isn't

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Batuhan Taskaya
In fact, that would be a cool feature for ORMs. IMHO instead of ugly call chain with filters, slicing is a better option (on `__class_getattr__`). As said there are some disadvantages but i think this proposal deserves a PEP. On Fri, Oct 4, 2019, 10:59 PM Caleb Donovick wrote: > While there is n

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Rhodri James
On 07/10/2019 14:52, Random832 wrote: On Mon, Oct 7, 2019, at 09:22, Rhodri James wrote: On 04/10/2019 20:34, Caleb Donovick wrote: The first and perhaps the most obvious, is doing relational queries. ``` where_x_1 = db[x=1] ``` is more beautiful than ``` where_x_1 = db[dict(x=1)] where_x_1 =

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Random832
On Mon, Oct 7, 2019, at 10:02, Rhodri James wrote: > It would still break a lot of user __getitem__ implementations IHMO. It is already possible to pass any object. The fact that passing an object that an object is not designed to accept won't get good results doesn't mean the ability to do so "

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Anders Hovmöller
> On 7 Oct 2019, at 16:36, Batuhan Taskaya wrote: > >  > In fact, that would be a cool feature for ORMs. IMHO instead of ugly call > chain with filters, slicing is a better option (on `__class_getattr__`). As > said there are some disadvantages but i think this proposal deserves a PEP. I re

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Rhodri James
On 07/10/2019 15:43, Random832 wrote: On Mon, Oct 7, 2019, at 10:02, Rhodri James wrote: It would still break a lot of user __getitem__ implementations IHMO. It is already possible to pass any object. The fact that passing an object that an object is not designed to accept won't get good resu

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Andrew Barnert via Python-ideas
On Oct 4, 2019, at 12:34, Caleb Donovick wrote: > > Allowing key value pairs in geitem need not change the interface of getitem. > All the key value pairs could be collected as a dict and passed to getitem > as the index. Similar to how the all the positional arguments are gather into > a si

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Kirill Balunov
Are you aware of PEP 472 https://www.python.org/dev/peps/pep-0472 ? Maybe you have something different in mind, but for me your idea looks pretty the same. While the PEP 472 is in Rejected, Abandoned section, I do not remember any serious criticism of this idea. It’s just that the authors of that p

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Christopher Barker
> Are you aware of PEP 472 https://www.python.org/dev/peps/pep-0472 ? > That is indeed the same idea, though perhaps the details are a bit different. This example from the PEP: gridValues[x=3, y=5, z=8] Makes me wonder: Should that yield the same results as: gridValues[3,5,8] Much like posit

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> Are you aware of PEP 472 https://www.python.org/dev/peps/pep-0472 ? Maybe you have something different in mind, but for me your idea looks pretty the same. While the PEP 472 is in Rejected, Abandoned section, I do not remember any serious criticism of this idea. It’s just that the authors of t

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Cameron Simpson
On 07Oct2019 10:56, Joao S. O. Bueno wrote: So, in short, your idea is to allow "=" signs inside `[]` get notation to be translated to dicts on the call, Subjectively that seems like a tiny tiny win. I'm quite -1 on this idea; language spec bloat to neglible gain. in the same way comma sep

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Cameron Simpson
On 08Oct2019 09:19, Cameron Simpson wrote: On 07Oct2019 10:56, Joao S. O. Bueno wrote: So, in short, your idea is to allow "=" signs inside `[]` get notation to be translated to dicts on the call, Subjectively that seems like a tiny tiny win. I'm quite -1 on this idea; language spec bloat t

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Random832
On Mon, Oct 7, 2019, at 18:19, Cameron Simpson wrote: > On 07Oct2019 10:56, Joao S. O. Bueno wrote: > >So, in short, your idea is to allow "=" signs inside `[]` get notation to > >be translated > >to dicts on the call, > > Subjectively that seems like a tiny tiny win. I'm quite -1 on this idea;

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Cameron Simpson
On 08Oct2019 09:19, Cameron Simpson wrote: Chris pointed out to me recently that tuples don't need commas, Cough, "brackets", cough. the commas alone suffice. You see brackets _around_ tuples a lot because of precedence. Reviewing my mail folder, it was actually Steven D'Aprano who pointed

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> I think it might be better if it actually passed them as keyword arguments. If only keyword arguments are passed what happens to the positional index? Is it the empty tuple? Currently subscript with no index (`dict()[]`) is a syntax error should it continue to be? > Also, I think there are us

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Joao S. O. Bueno
On Mon, 7 Oct 2019 at 19:19, Cameron Simpson wrote: > On 07Oct2019 10:56, Joao S. O. Bueno wrote: > >So, in short, your idea is to allow "=" signs inside `[]` get notation to > >be translated > >to dicts on the call, > > Subjectively that seems like a tiny tiny win. I'm quite -1 on this idea; >

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Andrew Barnert via Python-ideas
On Oct 7, 2019, at 14:56, Caleb Donovick wrote: > > > I think it might be better if it actually passed them as keyword arguments. > > If only keyword arguments are passed what happens to the positional index? > Is it the empty tuple? That seems like the obvious, and also most useful, answer.

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread MRAB
On 2019-10-07 23:22, Cameron Simpson wrote: On 08Oct2019 09:19, Cameron Simpson wrote: On 07Oct2019 10:56, Joao S. O. Bueno wrote: So, in short, your idea is to allow "=" signs inside `[]` get notation to be translated to dicts on the call, Subjectively that seems like a tiny tiny win. I'm

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Steven D'Aprano
On Mon, Oct 07, 2019 at 02:22:22PM +0100, Rhodri James wrote: > On 04/10/2019 20:34, Caleb Donovick wrote: > >``` > >where_x_1 = db[x=1] > >``` which would be equivalent to the existing syntax where_x_1 = db[{'x': 1}] [Rhodi] > OK, I'm not sure what you're trying to do here, which all on it

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Steven D'Aprano
On Tue, Oct 08, 2019 at 09:19:07AM +1100, Cameron Simpson wrote: > On 07Oct2019 10:56, Joao S. O. Bueno wrote: > >So, in short, your idea is to allow "=" signs inside `[]` get notation to > >be translated > >to dicts on the call, > > Subjectively that seems like a tiny tiny win. I'm quite -1 on t

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Steven D'Aprano
On Mon, Oct 07, 2019 at 05:18:39PM +0200, Anders Hovmöller wrote: > > > > On 7 Oct 2019, at 16:36, Batuhan Taskaya wrote: > > > >  > > In fact, that would be a cool feature for ORMs. IMHO instead of ugly call > > chain with filters, slicing is a better option (on `__class_getattr__`). As > >

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> Why not? What if I want a getitem that only has keyword arguments? I have to take the empty tuple as a positional argument, instead of just ensuring that the key is a dict. > Now, assuming you want to allow ** in getitem lookups I don't. *args are not allowed in subscripts either. However, t

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread David Mertz
It's really not a worthwhile win. It captures a tiny fraction of Pandas style filtering while complicating the syntax of Python. Here's another Pandas filter: db[db.x < 1] No help there with the next syntax. Here's another: db[(db.x == 1) | (db.y == 2)] A much better idea doesn't

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Chris Angelico
On Tue, Oct 8, 2019 at 12:47 PM Caleb Donovick wrote: > > > Why not? > > What if I want a getitem that only has keyword arguments? I have to take the > empty tuple as a positional argument, instead of just ensuring that the key > is a dict. > But what if you wanted to take both positional AND

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> But what if you wanted to take both positional AND keyword? I was suggesting that that wouldn't be allowed. So subscript either has a single argument, a tuple of arguments, or a dictionary of arguments. Allowing both has some advantages but is less cleanly integratible. -- Caleb Donovick On

[Python-ideas] Re: Allow kwargs in __{get|set|del|}item__

2019-10-07 Thread Caleb Donovick
> It captures a tiny fraction of Pandas style filtering while complicating the syntax of Python Sure maybe I we can't represent all filters super concisely but at least inequalities, or any filter on single axis, would not be hard. E.g. db[x=LT(1)] == db[db.x < 1] Granted I don’t really see a w