[Python-ideas] dict.merge(d1, d2, ...) (Counter proposal for PEP 584)

2019-03-04 Thread INADA Naoki
I think some people in favor of PEP 584 just want single expression for merging dicts without in-place update. But I feel it's abuse of operator overload. I think functions and methods are better than operator unless the operator has good math metaphor, or very frequently used as concatenate

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Serhiy Storchaka
04.03.19 21:24, Guido van Rossum пише: * Dicts are not like sets because the ordering operators (<, <=, >, >=) are not defined on dicts, but they implement subset comparisons for sets. I think this is another argument pleading against | as the operator to combine two dicts. Well, I suppose

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Anders Hovmöller
> Adding the + operator for dictionaries feels like it would be a mistake in > that it offers at most sugar-y benefits, but introduces the significant > drawback of making it easier to introduced unintended errors. I disagree. This argument only really applies to the case "a = a + b", not "a

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread INADA Naoki
On Tue, Mar 5, 2019 at 12:02 AM Stefan Behnel wrote: > > INADA Naoki schrieb am 04.03.19 um 11:15: > > Why statement is not enough? > > I'm not sure I understand why you're asking this, but a statement is "not > enough" because it's a statement and not an expression. It does not replace > the

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Brandt Bucher
I agree with David here. Subtraction wasn’t even part of the original discussion — it seems that it was only added as an afterthought because Guido felt they were natural to propose together and formed a nice symmetry. It’s odd that RHS values are not used at all, period. Further, there’s no

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Amber Yust
Adding the + operator for dictionaries feels like it would be a mistake in that it offers at most sugar-y benefits, but introduces the significant drawback of making it easier to introduced unintended errors. This would be the first instance of "addition" where the result can potentially

Re: [Python-ideas] Add a "week" function or attribute to datetime.date

2019-03-04 Thread Steve Barnes
If anybody is looking for such components then wx.DateTime (https://wxpython.org/Phoenix/docs/html/datetime_overview.html) it is derived from wxDateTime (https://docs.wxwidgets.org/3.1/classwx_date_time.html) and should support all of its methods including things like DST changes, etc.,

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Raymond Hettinger
> On Mar 4, 2019, at 11:24 AM, Guido van Rossum wrote: > > * Regarding how often this is needed, we know that this is proposed and > discussed at length every few years, so I think this will fill a real need. I'm not sure that conclusion follows from the premise :-) Some ideas get

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread David Foster
I have seen a ton of discussion about what dict addition should do, but have seen almost no mention of dict difference. This lack of discussion interest combined with me not recalling having needed the proposed subtraction semantics personally makes me wonder if we should hold off on locking

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Brett Cannon
On Mon, Mar 4, 2019 at 1:29 PM Neil Girdhar wrote: > On Mon, Mar 4, 2019 at 3:58 PM Christopher Barker > wrote: > > > > > > > > On Mon, Mar 4, 2019 at 12:41 PM Guido van Rossum > wrote: > >> > >> Honestly I would rather withdraw the subtraction operators than reopen > the discussion about

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread James Lu
By the way, my “no same keys with different values” proposal would not apply to +=. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread James Lu
> On Mar 4, 2019, at 11:25 AM, Steven D'Aprano wrote: > > The PEP gives a good example of when this "invariant" would be > unnecessarily restrictive: > >For example, updating default configuration values with >user-supplied values would most often fail under the >requirement

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread James Lu
> On Mon, Mar 04, 2019 at 10:01:23AM -0500, James Lu wrote: > > If you want to merge it without a KeyError, learn and use the more explicit > {**d1, **d2} syntax. On Mar 4, 2019, at 10:25 AM, Steven D'Aprano wrote: > In your previous email, you said the {**d ...} syntax was implicit: > >

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Guido van Rossum
On Mon, Mar 4, 2019 at 3:31 PM Del Gan wrote: > > the augmented assignment version allows anything the ``update`` method > allows, such as iterables of key/value pairs > > I am a little surprised by this choice. > > First, this means that "a += b" would not be equivalent to "a = a + > b". Is

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Dan Sommers
On 3/4/19 5:11 PM, Steven D'Aprano wrote: On Mon, Mar 04, 2019 at 11:56:54AM -0600, Dan Sommers wrote: On 3/4/19 10:44 AM, Steven D'Aprano wrote: > If you know ahead of time which order you want, you can simply reverse > it: > > # prefs = site_defaults + user_defaults + document_prefs >

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Del Gan
Hi. > the augmented assignment version allows anything the ``update`` method > allows, such as iterables of key/value pairs I am a little surprised by this choice. First, this means that "a += b" would not be equivalent to "a = a + b". Is there other built-in types which act differently if

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Steven D'Aprano
On Mon, Mar 04, 2019 at 11:56:54AM -0600, Dan Sommers wrote: > On 3/4/19 10:44 AM, Steven D'Aprano wrote: > > > If you know ahead of time which order you want, you can simply reverse > > it: > > > > # prefs = site_defaults + user_defaults + document_prefs > > prefs =

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Steven D'Aprano
On Sat, Mar 02, 2019 at 11:14:18AM -0800, Raymond Hettinger wrote: > If the existing code were in the form of "d=e.copy(); d.update(f); > d.update(g); d.update(h)", converting it to "d = e + f + g + h" would > be a tempting but algorithmically poor thing to do (because the > behavior is

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Paul Moore
On Mon, 4 Mar 2019 at 20:42, Guido van Rossum wrote: > > Honestly I would rather withdraw the subtraction operators than reopen the > discussion about making dict more like set. I'm neutral on dict addition, but dict subtraction seemed an odd extension to the proposal. Using b in a - b solely

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Neil Girdhar
On Mon, Mar 4, 2019 at 3:58 PM Christopher Barker wrote: > > > > On Mon, Mar 4, 2019 at 12:41 PM Guido van Rossum wrote: >> >> Honestly I would rather withdraw the subtraction operators than reopen the >> discussion about making dict more like set. I think that's unfortunate. > > > +1 > > I

Re: [Python-ideas] Add a "week" function or attribute to datetime.date

2019-03-04 Thread Christopher Barker
There are all sorts of "Calendar" operations one might want -- I think those belong in a separate library, rather than a few tacked on to datetime. -CHB On Fri, Mar 1, 2019 at 2:48 AM Robert Vanden Eynde wrote: > Currently one can do week = d.isocalendar()[1] > > The iso definition of a week

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Christopher Barker
On Mon, Mar 4, 2019 at 12:41 PM Guido van Rossum wrote: > Honestly I would rather withdraw the subtraction operators than reopen the > discussion about making dict more like set. > +1 I think the "dicts are like more-featured" sets is a math-geek perspective, and unlikely to make things more

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Guido van Rossum
Honestly I would rather withdraw the subtraction operators than reopen the discussion about making dict more like set. On Mon, Mar 4, 2019 at 12:33 PM Neil Girdhar wrote: > On Mon, Mar 4, 2019 at 3:22 PM Guido van Rossum wrote: > > > > On Mon, Mar 4, 2019 at 12:12 PM Neil Girdhar > wrote: >

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Neil Girdhar
On Mon, Mar 4, 2019 at 3:22 PM Guido van Rossum wrote: > > On Mon, Mar 4, 2019 at 12:12 PM Neil Girdhar wrote: >> >> On Mon, Mar 4, 2019 at 2:26 PM Guido van Rossum wrote: >> > >> > * Dicts are not like sets because the ordering operators (<, <=, >, >=) >> > are not defined on dicts, but they

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Guido van Rossum
On Mon, Mar 4, 2019 at 12:12 PM Neil Girdhar wrote: > On Mon, Mar 4, 2019 at 2:26 PM Guido van Rossum wrote: > > > > * Dicts are not like sets because the ordering operators (<, <=, >, >=) > are not defined on dicts, but they implement subset comparisons for sets. I > think this is another

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Neil Girdhar
On Mon, Mar 4, 2019 at 2:26 PM Guido van Rossum wrote: > > * Dicts are not like sets because the ordering operators (<, <=, >, >=) are > not defined on dicts, but they implement subset comparisons for sets. I think > this is another argument pleading against | as the operator to combine two >

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Guido van Rossum
* Dicts are not like sets because the ordering operators (<, <=, >, >=) are not defined on dicts, but they implement subset comparisons for sets. I think this is another argument pleading against | as the operator to combine two dicts. * Regarding how to construct the new set in __add__, I now

Re: [Python-ideas] Current use of addition in Python

2019-03-04 Thread Jonathan Fine
First, I thank Rhodri for his question, and Eric for his reply (see earlier messages in this thread). SUMMARY I record the addition properties of collections.Counter and numpy.array. Finally, some comments about len(), and a promise of more tomorrow. COUNTER Now for collections.Counter -- this

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread David Mertz
On Mon, Mar 4, 2019, 11:45 AM Steven D'Aprano wrote: > > Like other folks in the thread, I also want to merge dicts three times > per > > year. > > I'm impressed that you have counted it with that level of accuracy. Is it > on the same three days each year, or do they move about? *wink* > To be

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Dan Sommers
On 3/4/19 10:44 AM, Steven D'Aprano wrote: > If you know ahead of time which order you want, you can simply reverse > it: > > # prefs = site_defaults + user_defaults + document_prefs > prefs = dict(ChainMap(document_prefs, user_defaults, site_defaults)) > > but that seems a little

Re: [Python-ideas] Current use of addition in Python

2019-03-04 Thread Eric V. Smith
> On Mar 4, 2019, at 2:18 PM, Rhodri James wrote: > >> On 04/03/2019 14:03, Jonathan Fine wrote: >> Summary: This thread is for recording current use of addition in >> Python. > > TL;DR. Why is this is Python Ideas? Because of the current discussion of dict + dict. I think this is helping

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Steven D'Aprano
On Mon, Mar 04, 2019 at 03:43:48PM +0200, Serhiy Storchaka wrote: > 01.03.19 12:44, Steven D'Aprano пише: > >On Fri, Mar 01, 2019 at 08:47:36AM +0200, Serhiy Storchaka wrote: > > > >>Currently Counter += dict works and Counter + dict is an error. With > >>this change Counter + dict will return a

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Rhodri James
On 04/03/2019 15:12, James Lu wrote: On Mar 4, 2019, at 10:02 AM, Stefan Behnel wrote: INADA Naoki schrieb am 04.03.19 um 11:15: Why statement is not enough? I'm not sure I understand why you're asking this, but a statement is "not enough" because it's a statement and not an expression.

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Steven D'Aprano
On Mon, Mar 04, 2019 at 09:42:53AM -0500, David Mertz wrote: > On Mon, Mar 4, 2019, 8:30 AM Serhiy Storchaka wrote: > > > But is merging two dicts a common enough problem that needs introducing > > an operator to solve it? I need to merge dicts maybe not more than one > > or two times by year,

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Steven D'Aprano
On Mon, Mar 04, 2019 at 10:09:32AM -0500, James Lu wrote: > How many situations would you need to make a copy of a dictionary and > then update that copy and override old keys from a new dictionary? Very frequently. That's why we have a dict.update method, which if I remember correctly, was

Re: [Python-ideas] Current use of addition in Python

2019-03-04 Thread Rhodri James
On 04/03/2019 14:03, Jonathan Fine wrote: Summary: This thread is for recording current use of addition in Python. TL;DR. Why is this is Python Ideas? -- Rhodri James *-* Kynesim Ltd ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Steven D'Aprano
On Mon, Mar 04, 2019 at 10:01:23AM -0500, James Lu wrote: > If you want to merge it without a KeyError, learn and use the more explicit > {**d1, **d2} syntax. In your previous email, you said the {**d ...} syntax was implicit: In other words, explicit + is better than implicit {**, **#,

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread James Lu
> On Mar 4, 2019, at 10:02 AM, Stefan Behnel wrote: > > INADA Naoki schrieb am 04.03.19 um 11:15: >> Why statement is not enough? > > I'm not sure I understand why you're asking this, but a statement is "not > enough" because it's a statement and not an expression. It does not replace > the

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Stefan Behnel
INADA Naoki schrieb am 04.03.19 um 11:15: > Why statement is not enough? I'm not sure I understand why you're asking this, but a statement is "not enough" because it's a statement and not an expression. It does not replace the convenience of an expression. Stefan

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread James Lu
> On Mar 4, 2019, at 3:41 AM, Stefan Behnel wrote: > > James Lu schrieb am 04.03.19 um 03:28: >> I propose that the + sign merge two python dictionaries such that if there >> are conflicting keys, a KeyError is thrown. > > Please, no. That would be really annoying. > > If you need that

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread David Mertz
On Mon, Mar 4, 2019, 8:30 AM Serhiy Storchaka wrote: > But is merging two dicts a common enough problem that needs introducing > an operator to solve it? I need to merge dicts maybe not more than one > or two times by year, and I am fine with using the update() method. > Perhaps {**d1, **d2} can

[Python-ideas] Current use of addition in Python

2019-03-04 Thread Jonathan Fine
Summary: This thread is for recording current use of addition in Python. This post covers the built-in types. I'll do Counter and numpy.array in another post. Please use another thread to discuss possible possible future use of addition. BACKGROUND At present constructions such as {'a': 1} +

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Serhiy Storchaka
01.03.19 12:44, Steven D'Aprano пише: On Fri, Mar 01, 2019 at 08:47:36AM +0200, Serhiy Storchaka wrote: Currently Counter += dict works and Counter + dict is an error. With this change Counter + dict will return a value, but it will be different from the result of the += operator. That's how

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread INADA Naoki
On Mon, Mar 4, 2019 at 10:29 PM Serhiy Storchaka wrote: > > It is not that I like to add an operator for dict merging, but dicts are > more like sets than sequences: they can not contain duplicated keys and > the size of the result of merging two dicts can be less than the sum of > their sizes.

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Serhiy Storchaka
01.03.19 21:31, Guido van Rossum пише: On Thu, Feb 28, 2019 at 10:30 PM Serhiy Storchaka > wrote: And this opens a non-easy problem: how to create a mapping of the same type? Not all mappings, and even not all dict subclasses have a copying constructor.

Re: [Python-ideas] Left arrow and right arrow operators

2019-03-04 Thread Todd
What is the operator supposed to do? On Sun, Mar 3, 2019, 09:52 francismb wrote: > Hi, > the idea here is just to add the __larrow__ and __rarrow__ operators for > <- and ->. > > > E.g. of use on dicts : > >>> d1 = {'a':1, 'b':1 } > >>> d2 = {'a':2 } > >>> d3 = d1 -> d2 > >>> d3 > {'a':1, 'b':1

Re: [Python-ideas] Left arrow and right arrow operators

2019-03-04 Thread Calvin Spealman
I don't like the idea of arrows in both directions when you can just swap the operands instead On Sun, Mar 3, 2019 at 9:52 AM francismb wrote: > Hi, > the idea here is just to add the __larrow__ and __rarrow__ operators for > <- and ->. > > > E.g. of use on dicts : > >>> d1 = {'a':1, 'b':1 } >

Re: [Python-ideas] Dict joining using + and +=

2019-03-04 Thread Ivan Levkivskyi
On Sat, 2 Mar 2019 at 19:15, Raymond Hettinger wrote: > > > On Mar 1, 2019, at 11:31 AM, Guido van Rossum wrote: > > > > There's a compromise solution for this possible. We already do this for > Sequence and MutableSequence: Sequence does *not* define __add__, but > MutableSequence *does*

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Jimmy Girardet
> but requires either some obscure syntax or a statement instead of a simple > expression. > > The proposal is to enable the obvious syntax for something that should be > obvious. > > Stefan The discussions on this list show that the behavior of `+` operator with dict will never be obvious

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread INADA Naoki
On Mon, Mar 4, 2019 at 6:52 PM Stefan Behnel wrote: > > I think the main intentions is to close a gap in the language. > > [1,2,3] + [4,5,6] > > works for lists and tuples, > > {1,2,3} | {4,5,6} > > works for sets, but joining two dicts isn't simply > > {1:2, 3:4} + {5:6} > Operators

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Stefan Behnel
Jimmy Girardet schrieb am 04.03.19 um 10:12: > I'm not old on this list but every time there is a proposal, the answer > is "what are you trying to solve ?". > > Since > > |z ={**x,**y} and z.update(y) Exists, I can"t find the answer. I think the main intentions is to close a gap in the

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Jimmy Girardet
Hi, I'm not old on this list but every time there is a proposal, the answer is "what are you trying to solve ?". Since |z ={**x,**y} and z.update(y) Exists, I can"t find the answer. | | | Le 02/03/2019 à 04:52, Steven D'Aprano a écrit : > Executive summary: > > - I'm going to argue for

Re: [Python-ideas] PEP: Dict addition and subtraction

2019-03-04 Thread Stefan Behnel
James Lu schrieb am 04.03.19 um 03:28: > I propose that the + sign merge two python dictionaries such that if there > are conflicting keys, a KeyError is thrown. Please, no. That would be really annoying. If you need that feature, it can become a new method on dicts. Stefan