[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Brandt Bucher
Thanks for your response Serhiy. > Yes, but this is a different thing. You must to implement new __or__ in a > subclass to make the behavior of d1 | d2 be different from {**d1, **d2}. Really? I'm sorry, but this doesn't feel like a real argument to me. There was no clear compatible path

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Claudio Jolowicz
Let me split my case into two points: 1) The intuition that the right-hand side of `a | b` is a fallback value 2) The claim that `a |= b` is a common idiom to assign defaults About 2) It appears that the idiom in 2) is less common than I assumed. My expectations were shaped by working with a

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Chris Angelico
On Thu, Feb 27, 2020 at 8:15 PM Serhiy Storchaka wrote: > > 27.02.20 10:46, Chris Angelico пише: > > On Thu, Feb 27, 2020 at 7:41 PM Serhiy Storchaka > > wrote: > >> sympy/utilities/runtests.py > >> > >> Sorry, but the current code > >> > >> globs = globs.copy() > >> if extraglobs is not None:

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Kyle Stanley
> So I've also never come across "|=" being used for this purpose. IIRC, the JavaScript implementation of "|=" can potentially be used in the way Claudio described it, instead it's based on the truthiness of the left-hand operand rather than it being "unset". But it works in that context because

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Serhiy Storchaka
27.02.20 10:46, Chris Angelico пише: On Thu, Feb 27, 2020 at 7:41 PM Serhiy Storchaka wrote: sympy/utilities/runtests.py Sorry, but the current code globs = globs.copy() if extraglobs is not None: globs.update(extraglobs) looks much clearer to me than the proposed globs = globs |

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Chris Angelico
On Thu, Feb 27, 2020 at 7:41 PM Serhiy Storchaka wrote: > sympy/utilities/runtests.py > > Sorry, but the current code > > globs = globs.copy() > if extraglobs is not None: > globs.update(extraglobs) > > looks much clearer to me than the proposed > > globs = globs | (extraglobs if extraglobs

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-27 Thread Serhiy Storchaka
18.02.20 19:35, Brandt Bucher пише: ...it was decided that `d1 | d2` also should ignore the types of the operands and always return a dict. And it accepts only dicts, not general mappings, in difference to `{**d1, **d2}`. So the only disadvantage of `{**d1, **d2}` is that it is not well known

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-26 Thread Antoine Rozo
Maybe it's more the `a ||= b` that acts like a `a = a or b` in Python? But then I don't think there is a confusion on Python side because languages with a || operator usually already has a simple | with a different meaning. Le jeu. 27 févr. 2020 à 00:28, Nick Coghlan a écrit : > > > > On Thu.,

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-26 Thread Nick Coghlan
On Thu., 27 Feb. 2020, 2:03 am Guido van Rossum, wrote: > On Wed, Feb 26, 2020 at 7:43 AM Claudio Jolowicz > wrote: > >> In my experience, the expression `value |= other` is a common idiom across >> programming languages to provide a default for `value` if it is "unset". >> > > Interesting. Can

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-26 Thread Guido van Rossum
Here's our current proposal for docs. Is there anything you'd like to add? https://github.com/python/cpython/pull/18659/files On Wed, Feb 26, 2020 at 8:12 AM David Mertz wrote: > I think the "if unset" behavior is well handled by collections.ChainMap. > But I do think that fact should be

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-26 Thread David Mertz
I think the "if unset" behavior is well handled by collections.ChainMap. But I do think that fact should be prominent in any documentation of the new dict Union operator. On Wed, Feb 26, 2020, 11:06 AM Guido van Rossum wrote: > On Wed, Feb 26, 2020 at 7:43 AM Claudio Jolowicz > wrote: > >> In

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-26 Thread Guido van Rossum
On Wed, Feb 26, 2020 at 7:43 AM Claudio Jolowicz wrote: > In my experience, the expression `value |= other` is a common idiom across > programming languages to provide a default for `value` if it is "unset". > For a > container-type, I would expect this operation, informally spoken, to be >

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-26 Thread Claudio Jolowicz
First off, apologies for entering the discussion after it has formally ended. I'm not sure this has any relevance now that the PEP is accepted and the reference implementation merged. If not, sorry and feel free to ignore. "Leftmost Value (First-Seen) Wins" was rejected because > it is not clear

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-25 Thread Nick Coghlan
On Mon, 24 Feb 2020 at 12:10, Guido van Rossum wrote: > > On Sat, Feb 22, 2020 at 4:45 PM Brandt Bucher wrote: >> >> [quoting Nick] >> > collections.Mapping and collections.MutableMapping could provide concrete >> > method implementations that make subclasses behave in a way that's similar >>

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-24 Thread Guido van Rossum
On Mon, Feb 24, 2020 at 10:42 AM Brandt Bucher wrote: > > Are these three cookie classes sufficiently popular that we need to > support `|` on them? > > I don't have much experience with `http`, so I figured I'd open a BPO > issue and let the relevant folks make the call. The main reason I'm >

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-24 Thread Brandt Bucher
> Are these three cookie classes sufficiently popular that we need to support > `|` on them? I don't have much experience with `http`, so I figured I'd open a BPO issue and let the relevant folks make the call. The main reason I'm considering these is that `Morsel` was updated back in 3.5 with

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-23 Thread Guido van Rossum
On Sat, Feb 22, 2020 at 10:09 PM Steven D'Aprano wrote: > On Tue, Feb 18, 2020 at 05:35:38PM -, Brandt Bucher wrote: > > > I am accepting this PEP. Congratulations Steven and Brandt! > > > > Thank you for your guidance, especially the suggestions late last > > year. And thanks Steven for

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-23 Thread Guido van Rossum
On Sat, Feb 22, 2020 at 4:45 PM Brandt Bucher wrote: > [quoting Nick] > > collections.Mapping and collections.MutableMapping could provide > concrete method implementations that make subclasses behave in a way that's > similar to built-in dicts > > Hm, haven't thought too much about this (I

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-23 Thread Guido van Rossum
On Sat, Feb 22, 2020 at 11:28 AM Brandt Bucher wrote: > Just to follow up on this, here are the subclasses I've found. > > Should be updated: > - collections.OrderedDict > - collections.defaultdict > SGTM. - http.cookies.BaseCookie > - http.cookies.Morsel > - http.cookies.SimpleCookie > Are

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-22 Thread Steven D'Aprano
On Tue, Feb 18, 2020 at 05:35:38PM -, Brandt Bucher wrote: > > I am accepting this PEP. Congratulations Steven and Brandt! > > Thank you for your guidance, especially the suggestions late last > year. And thanks Steven for taking me on as a co-author and shaping > the bulk of the proposal.

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-22 Thread Brandt Bucher
> we'll also want to look at collections.UserDict, collections.ChainMap, and > types.MappingProxyType. UserDict has already been updated in the PR (it has tests that fail if it doesn't have all of dict's methods). I'll look into the others... thanks for reminding me! > collections.Mapping and

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-22 Thread Nick Coghlan
On Sun., 23 Feb. 2020, 5:32 am Brandt Bucher, wrote: > Just to follow up on this, here are the subclasses I've found. > > Should be updated: > - collections.OrderedDict > - collections.defaultdict > - http.cookies.BaseCookie > - http.cookies.Morsel > - http.cookies.SimpleCookie > They're not

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-22 Thread Brandt Bucher
Just to follow up on this, here are the subclasses I've found. Should be updated: - collections.OrderedDict - collections.defaultdict - http.cookies.BaseCookie - http.cookies.Morsel - http.cookies.SimpleCookie Don’t think so: - typing.TypedDict Already defines the operator: -

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-18 Thread Brandt Bucher
> In particular, you may want to update the implementations of defaultdict and > ordereddict. (are there others?) I have a checklist for PEP 584 follow-up PRs I'm planning to make after (and if) it is accepted. typeshed stubs, docs, and `defaultdict` were on it. I'll add `OrderedDict` as well

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-18 Thread Guido van Rossum
On Tue, Feb 18, 2020 at 9:40 AM Brandt Bucher wrote: > > Now, addressing Serhiy's points :)... > > > ...it was decided that `d1 | d2` also should ignore the types of the > operands and always return a dict. And it accepts only dicts, not general > mappings, in difference to `{**d1, **d2}`. So

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-18 Thread Brandt Bucher
> I am accepting this PEP. Congratulations Steven and Brandt! Thank you for your guidance, especially the suggestions late last year. And thanks Steven for taking me on as a co-author and shaping the bulk of the proposal. > Hm, the PEP should probably also link to that PR rather than to

[Python-Dev] Re: Accepting PEP 584: Add Union Operators To dict

2020-02-17 Thread Serhiy Storchaka
17.02.20 23:02, Guido van Rossum пише: Now that the last bits of discussion about PEP 584 have been settled (we will *not* be calling the `copy` or `update` methods) I am accepting this PEP. Congratulations Steven and Brandt! Thanks to everyone else who gave their opinion. Formally, I will