[Python-ideas] Adding "+" and "+=" operators to dict

Petr Viktorin encukou at gmail.com
Fri Feb 13 10:26:41 CET 2015


On Fri, Feb 13, 2015 at 4:52 AM, Andrew Barnert
<abarnert at yahoo.com.dmarc.invalid> wrote:
> On Feb 12, 2015, at 18:45, Steven D'Aprano <steve at pearwood.info> wrote:
>
>> On Thu, Feb 12, 2015 at 07:25:24PM -0700, Eric Snow wrote:
>>
>>> Or just make "dict(a, b, c)" work.
>>
>> I've come to the same conclusion.

>> - Surely this change is minor enough that it doesn't need a PEP? It just
>>  needs a patch and approval from a senior developer with commit
>>  privileges.
>
> I'm not sure about this. If you want to change MutableMapping.update too, you'll be potentially breaking all kinds of existing classes that claim to be a MutableMapping and override update with a method with a now-incorrect signature.

Is there a mechanism to evolve ABCs? Maybe there should be, something like:

- For a few Python versions, say that the new behavior is preferred
but can't be relied upon. Update the MutableMapping default
implementation (this is backwards compatible).
- Possibly, later, have MutableMapping warn when a class with the old
update signature is registered. (With the signature improvements in
py3, this should be possible for 99% cases.) Or just rely on linters
to implement a check.
- Finally switch over completely, so callers can rely on the new
MutableMapping.update


More information about the Python-ideas mailing list