[Python-ideas] PEP: Dict addition and subtraction

Rémi Lapeyre remi.lapeyre at henki.fr
Thu Mar 21 13:26:04 EDT 2019


Le 21 mars 2019 à 17:43:31, Steven D'Aprano
(steve at pearwood.info(mailto:steve at pearwood.info)) a écrit:

> I'd like to make a plea to people:
>
> I get it, there is now significant opposition to using the + symbol for
> this proposed operator. At the time I wrote the first draft of the PEP,
> there was virtually no opposition to it, and the | operator had very
> little support. This has clearly changed.
>
> At this point I don't think it is productive to keep making subjective
> claims that + will be more confusing or surprising. You've made your
> point that you don't like it, and the next draft^1 of the PEP will make
> that clear.
>
> But if you have *concrete examples* of code that currently is easy to
> understand, but will be harder to understand if we add dict.__add__,
> then please do show me!
>
> For those who oppose the + operator, it will help me if you made it
> clear whether it is *just* the + symbol you dislike, and would accept
> the | operator instead, or whether you hate the whole operator concept
> regardless of how it is spelled.

Thanks for the work you are doing on this PEP and for debunking my
misconceptions regarding types, I’m currently learning a lot about them.

I don’t know if it matters but I’m in favor of the method

> And to those who support this PEP, code examples where a dict merge
> operator will help are most welcome!

Not matter the notation you end up choosing, I think this code:
https://github.com/jpadilla/pyjwt/blob/master/jwt/utils.py#L71-L81

which is part of a widely used library to validate JWTs would greatly
benefit from a new merge to merge dicts. (This package is 78 on
https://hugovk.github.io/top-pypi-packages/)

Rémi

> ^1 Coming Real Soon Now™.
>
>
> --
> Steven
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list