[proxy] web.archive.org← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

bpo-36144: Dictionary Union (PEP 584) by brandtbucher · Pull Request #12088 · python/cpython

brandtbucher

Conversation

`d1 + d2` is semantically identical to `d3 = d1.copy(); d3.update(d2); d3`, and `d1 += d2` is semantically identical to `d1.update(d2)`.

Isn't that sweet?
It feels so weird to sum dicts like this... cool.
This gets the collections tests passing again.
This adds one test with 5 new assertions.
In case this gets pulled. Very cool!
Whoops.
This whole patch adds 3 new objects with docstrings: dict.__add__, dict.__radd__, dict.__iadd__. On some builds, this puts us over the threshold, so bump the count!

Replaces two places where a failed PyDict_Update call returns NotImplemented instead of raising the error.
This brings this reference implementation in line with PEP 584's spec.

Separately, allows RHS of += to be any valid arg to dict.update.
These are implemented as they are currently laid out in PEP 584.
This should get tests passing again.
And... we're officially implemented!

…nto addiction

brandtbucher changed the title bpo-36144: Dictionary addition. bpo-36144: Dictionary Addition/Subtraction (PEP 584)

Mar 2, 2019
This fixes issues where iteration errors could be swallowed, and also stops a possible reference leak.
This also implements the complex keys/__iter__ dance that update uses, as an example of compatibility with dict.update.
dict.__iadd__ can take any mapping (i.e., a list).
This is pretty much copied-and-pasted from UserDict, but it's better than what we had before. They may need some tweaking.
This was requested by Steven for comparison purposes. The final implementation will only keep one!

gvanrossum merged commit eb8ac57 into python:master

Feb 25, 2020

9 checks passed

Azure Pipelines PR #20200217.14 succeeded

Details

bedevere/issue-number Issue number 36144 found

Details

bedevere/news News entry found in Misc/NEWS.d

continuous-integration/travis-ci/pr The Travis CI build passed

Details

chrisburr added a commit to chrisburr/cpython that referenced this pull request

Dec 9, 2020