[Python-ideas] Re: Conditional dict declarations

2019-09-09 Thread Andrew Barnert via Python-ideas
On Sep 9, 2019, at 17:43, Steven D'Aprano wrote: > > But for me, I am not comfortable with this style and > would not use it because I have seen far too many people (including > myself) waste too much time farting about fixing formatting and > alignment issues instead of doing productive work.

[Python-ideas] Re: Conditional dict declarations

2019-09-09 Thread Steven D'Aprano
On Sat, Sep 07, 2019 at 08:22:58PM +0100, Rob Cliffe via Python-ideas wrote: > in which of the following is it easier to spot the mistake? > > # Version 1: >  if max_results > 0: querydata['max_results'] = max_results > if active is not None : querydata['active'] = active >

[Python-ideas] Re: Conditional dict declarations

2019-09-09 Thread Rob Cliffe via Python-ideas
On 08/09/2019 19:34:33, Chris Angelico wrote: On Mon, Sep 9, 2019 at 4:13 AM Rob Cliffe via Python-ideas wrote: On 07/09/2019 18:59:49, Chris Angelico wrote: On Sat, Sep 7, 2019 at 11:27 PM Rob Cliffe via Python-ideas wrote: A chance for me to bang the drum on one of my pet themes: Someti

[Python-ideas] Re: Conditional dict declarations

2019-09-08 Thread Andrew Barnert via Python-ideas
On Sep 8, 2019, at 11:34, Chris Angelico wrote: > > You're right that the triple repeated name is not caused by your > style. However, your suggestion also doesn't solve it. What I'd > probably want to do, here, is build the dictionary with everything, > and then have a separate pass that removes

[Python-ideas] Re: Conditional dict declarations

2019-09-08 Thread Chris Angelico
On Mon, Sep 9, 2019 at 4:13 AM Rob Cliffe via Python-ideas wrote: > > On 07/09/2019 18:59:49, Chris Angelico wrote: > > On Sat, Sep 7, 2019 at 11:27 PM Rob Cliffe via Python-ideas > > wrote: > >> A chance for me to bang the drum on one of my pet themes: > >> Sometimes the readability of code is i

[Python-ideas] Re: Conditional dict declarations

2019-09-08 Thread Rob Cliffe via Python-ideas
On 07/09/2019 18:59:49, Chris Angelico wrote: On Sat, Sep 7, 2019 at 11:27 PM Rob Cliffe via Python-ideas wrote: A chance for me to bang the drum on one of my pet themes: Sometimes the readability of code is improved by breaking the sacred taboo of 1 statement per line, if it allows similar c

[Python-ideas] Re: Conditional dict declarations

2019-09-07 Thread Chris Angelico
On Sat, Sep 7, 2019 at 11:27 PM Rob Cliffe via Python-ideas wrote: > A chance for me to bang the drum on one of my pet themes: > Sometimes the readability of code is improved by breaking the sacred > taboo of 1 statement per line, if it allows similar constructs to be > vertically aligned: > >

[Python-ideas] Re: Conditional dict declarations

2019-09-07 Thread Joao S. O. Bueno
On Sat, 7 Sep 2019 at 01:24, Steven D'Aprano wrote: > On Sat, Sep 07, 2019 at 12:35:09AM -0300, Joao S. O. Bueno wrote: > > > Well - the idea showed up here, and got an immediate "that is nice, let's > > do it" from you, followed by approval from a lot more people, and > > very little controverse

[Python-ideas] Re: Conditional dict declarations

2019-09-07 Thread Rob Cliffe via Python-ideas
On 04/09/2019 23:25:32, r...@hwyl.org wrote: Hi list I have a proposal for a minor (improvement?) to dict declarations. I find a common requirement I have is to include one or more entries in a dict only if some condition is met. Currently, the usual way of doing that is to add one or more

[Python-ideas] Re: Conditional dict declarations

2019-09-06 Thread Steven D'Aprano
On Sat, Sep 07, 2019 at 12:35:09AM -0300, Joao S. O. Bueno wrote: > Well - the idea showed up here, and got an immediate "that is nice, let's > do it" from you, followed by approval from a lot more people, and > very little controverse. So, it is pretty much "approved", even if not yet > detailed

[Python-ideas] Re: Conditional dict declarations

2019-09-06 Thread Joao S. O. Bueno
On Fri, 6 Sep 2019 at 01:54, Guido van Rossum wrote: > On Thu, Sep 5, 2019 at 8:37 PM Joao S. O. Bueno > wrote: > >> Also, if one have in mind that dict addition with the `+` operator had >> been >> recelently approved >> > > Where did you hear this? I am not aware that this was even made into a

[Python-ideas] Re: Conditional dict declarations

2019-09-06 Thread Andrew Barnert via Python-ideas
On Friday, September 6, 2019, 11:22:08 AM PDT, Rich Smith wrote: > On Thu, 5 Sep 2019 at 16:51, Andrew Barnert wrote: >> You say here “the dict insertion code” does it. Would they mean >> d[key]=d.skip doesn’t insert anything? > Yes. OK, then I go from +0 on your proposal to -1. Constructing d

[Python-ideas] Re: Conditional dict declarations

2019-09-06 Thread Rich Smith
On Thu, 5 Sep 2019 at 16:51, Andrew Barnert wrote: > > You say here “the dict insertion code” does it. Would they mean > d[key]=d.skip doesn’t insert anything? Yes. If so, then how could I put skip in a dict at all? The intention is that you couldn't. This could raise some implementation iss

[Python-ideas] Re: Conditional dict declarations

2019-09-06 Thread Brandt Bucher
Just to be clear, PEP 584 (dictionary operators) is currently in draft form and is undergoing a new round of revisions. Nothing has been finalized, much less approved. Brandt ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Guido van Rossum
On Thu, Sep 5, 2019 at 8:37 PM Joao S. O. Bueno wrote: > Also, if one have in mind that dict addition with the `+` operator had been > recelently approved > Where did you hear this? I am not aware that this was even made into a PEP let alone that such a PEP was approved. -- --Guido van Rossum

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Joao S. O. Bueno
Also, if one have in mind that dict addition with the `+` operator had been recelently approved, as of Python 3.9 it will be ok to write: ``` return ({ 'user_id': user_id,} + ({'max_results': max_results} if max_results else {}) + ({'active': active} if active is not None

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Andrew Barnert via Python-ideas
> On Sep 5, 2019, at 07:46, Sebastian Kreft wrote: > > How is this different to the discussion > https://mail.python.org/archives/list/python-ideas@python.org/thread/MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27/#MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27 > ? Well, that discussion started with an unworkable proposal

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Brandt Bucher
Also worth noting is that dict.skip would live in dict.__dict__... which is a dict. Brandt > On Sep 5, 2019, at 08:51, Andrew Barnert via Python-ideas > wrote: > >> On Sep 4, 2019, at 15:25, r...@hwyl.org wrote: >> >> ..."skip" being a unique object defined in and accessible from dict (there

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Andrew Barnert via Python-ideas
On Sep 4, 2019, at 15:25, r...@hwyl.org wrote: > > ..."skip" being a unique object defined in and accessible from dict (there > may be better places to make it available). The dict insertion code then > simply ignores those entries when creating the dict. I’m a bit confused about exactly when t

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Sebastian Kreft
How is this different to the discussion https://mail.python.org/archives/list/python-ideas@python.org/thread/MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27/#MFSL3U6V74PZN4AT4JFQMQXSMGOJ6F27 ? On Thu, Sep 5, 2019 at 9:24 AM wrote: > Okie, looks like my code got munched in the web view -- how do I make > i

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread brian . skinn
Okie, looks like my code got munched in the web view -- how do I make it not do that? ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread brian . skinn
I thought of something similar, but where the dict-literal construction is desired: >>> foo = True >>> bar = False >>> baz = False >>> d = { ... 'foo' if foo else None: 1, ... 'bar' if bar else None: 2, ... 'baz' if baz else None: 3, ... } >>> d {'foo': 1, None: 3} >>> d.pop(None) 3 >>> d {

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Richard Musil
I was thinking more in this direction: d = dict() d[action in not None and 'action'] = action d[minval > 0 and 'minval'] = minval ... del d[False] There are few things I do not particularly like about this (assigning to dict, even when value is discarded later, or necessity of the del d[False]),

[Python-ideas] Re: Conditional dict declarations

2019-09-05 Thread Paul Moore
On Thu, 5 Sep 2019 at 11:19, wrote: > I find a common requirement I have is to include one or more entries in a > dict only if some condition is met. Currently, the usual way of doing that is > to add one or more if statements. > > Simple (but hopefully relatable-to-real-world-code) example. [..