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

2019-02-28 Thread Serhiy Storchaka
01.03.19 06:21, Guido van Rossum пише: On Wed, Feb 27, 2019 at 11:18 PM Serhiy Storchaka > wrote: Counter uses + for a *different* behavior!  >>> Counter(a=2) + Counter(a=3) Counter({'a': 5}) Well, you can see this as a special case. The proposed +

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

2019-02-28 Thread Adrien Ricocotam
I really like this idea. It’s not obvious how to deal with key conflicts and I don’t think replacing by the keys of the second dict is that obviously a good behaviour. With the actual merging ({**d1, **d2}) it works the same as when you build a custom dict so it’s usually known by people. If we

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

2019-02-28 Thread Serhiy Storchaka
28.02.19 23:19, Greg Ewing пише: Serhiy Storchaka wrote: I do not understand why we discuss a new syntax for dict merging if we already have a syntax for dict merging: {**d1, **d2} (which works with *all* mappings). But that always returns a dict. A '+' operator could be implemented by other

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

2019-02-28 Thread fhsxfhsx
Considering potential ambiguity, I suggest `d1.append(d2)` so we can have an additional argument saying `d1.append(d2, mode="some mode that tells how this function behaviours")`. If we are really to have the new syntax `d1 + d2`, I suggest leaving it for `d1.append(d2, mode="strict")` which

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

2019-02-28 Thread Steven D'Aprano
On Thu, Feb 28, 2019 at 08:59:30PM -0800, Hasan Diwan wrote: > Do we really need a "+" and a "-" operation on dictionaries? > [dictinstance.update({k:v}) for k,v in dictinstance.items()] does handle > merges already. I don;t think that does what you intended. That merges dictinstance with

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

2019-02-28 Thread Hasan Diwan
Do we really need a "+" and a "-" operation on dictionaries? [dictinstance.update({k:v}) for k,v in dictinstance.items()] does handle merges already. And I'm assuming that "-" should return the difference -- set(d1.keys()) - set(d2.keys()), right? -- H -- OpenPGP:

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

2019-02-28 Thread Karthikeyan
The PEP should probably also propose d1-d2. > What would be the output of this? Does this return a new dictionary where keys in d2 are removed in d1 like sets? >>> d = dict((i, i) for i in range(5)) >>> e = dict((i, i) for i in range(4, 10)) >>> d {0: 0, 1: 1, 2: 2, 3: 3, 4: 4} >>> e {4: 4, 5:

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

2019-02-28 Thread Guido van Rossum
On Wed, Feb 27, 2019 at 11:18 PM Serhiy Storchaka wrote: > 27.02.19 20:48, Guido van Rossum пише: > > > > On Wed, Feb 27, 2019 at 10:42 AM Michael Selik > > > > wrote > The dict subclass > collections.Counter overrides the update method > > for adding values

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

2019-02-28 Thread Greg Ewing
Serhiy Storchaka wrote: I do not understand why we discuss a new syntax for dict merging if we already have a syntax for dict merging: {**d1, **d2} (which works with *all* mappings). But that always returns a dict. A '+' operator could be implemented by other mapping types to return a mapping

[Python-ideas] Allow async defs for __await__

2019-02-28 Thread Thomas Gläßle
Hi, I suggest to allow defining awaitable classes in terms of `async def`-s:     class FeynmanAlgorithm:     async def __await__(self):     await self.write_down_the_problem()             await self.think_real_hard()             await self.write_down_the_solution() IMO, this would

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

2019-02-28 Thread Karthikeyan
Just to add to the discussion this was brought up previously as part of PEP 448 unpacking generalizations that also added {**x, **y} to merge two dicts in Python 3.5. Previous python ideas thread : https://mail.python.org/pipermail/python-ideas/2015-February/031748.html LWN summary :

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

2019-02-28 Thread James Lu
I agree with Storchaka here. The advantage of existing dict merge syntax is that it will cause an error if the object is not a dict or dict-like object, thus preventing people from doing bad things. > On Feb 28, 2019, at 2:16 AM, Serhiy Storchaka wrote: > > 27.02.19 20:48, Guido van Rossum

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

2019-02-28 Thread Eric V. Smith
On 2/27/2019 2:08 PM, Guido van Rossum wrote: On Wed, Feb 27, 2019 at 11:06 AM João Matos > wrote: Great. Because I don't program in any other language except Python, I can't make the PR (with the C code). Maybe someone who program in C can help?