Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-36144: Dictionary Union (PEP 584) #12088
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 comment has been minimized.
This comment has been minimized.
It usually isn't an effective use to time to go straight to a PR before a proposal has been discussed and accepted. |
This comment has been minimized.
This comment has been minimized.
I figured it would help with decision-making. The person who started the thread asked for an implementation, and I had the free time to make one. I'm not very familiar with how the PEP process usually works, but I saw in PEP 1:
Sorry if this is a distraction. It's not my intention to disrupt the normal process! |
Replaces two places where a failed PyDict_Update call returns NotImplemented instead of raising the error.
This comment has been minimized.
This comment has been minimized.
It looks like this may yet have a chance :-) |
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
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!
This comment has been minimized.
This comment has been minimized.
I agree with Serhiy.
On Thu, Feb 6, 2020 at 00:07 Serhiy Storchaka ***@***.***> wrote:
Because list and set do not call copy() and extend()/update().
It would make dict very different from other builtin types.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12088?email_source=notifications&email_token=AAWCWMUS4RJZZ5BMOQH224DRBPAMNA5CNFSM4G2X5HR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEK6JJ6Q#issuecomment-582784250>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAWCWMULOM22F7PTNNNJGM3RBPAMNANCNFSM4G2X5HRQ>
.
--
--Guido (mobile)
|
This comment has been minimized.
This comment has been minimized.
Since it is a principal point of the PEP, I suggest you to create two or more separate PRs: one does not depend on subclasses, and the other calls Yet one argument against calling |
This comment has been minimized.
This comment has been minimized.
@serhiy-storchaka Yes, and in the earlier stages of the proposal I felt as you did: But Steven was strongly for this, and over time his arguments were enough to shift my view. Also:
It's more common to subclass
|
This comment has been minimized.
This comment has been minimized.
@gvanrossum, is this enough of an issue that you would consider rejecting the proposal over it? I know that Steven and I have somewhat strongly formed opinions on this from all of the endless mailing-list threads, so it might be a good idea to continue this discussion on the python-dev thread where he can participate, if so. |
This comment has been minimized.
This comment has been minimized.
Also, @serhiy-storchaka it would be pretty easy to just strip the last 5 commits at this point. I can make another PR if the two designs deviate more substantially. |
This comment has been minimized.
This comment has been minimized.
@brandtbucher This won't be an issue unless you make it one. The proposal is a good one regardless of what it does with subclasses. Does the PEP explicitly address this (either in the spec or in the text about rejected alternatives or elsewhere)? If so can you point me to the text? A general problem with honoring subclasses is that it's worse when it's done inconsistently than not at all. For immutable objects (e.g. Steven's int subclassing example) the problem is that you won't know the arguments to the subclass constructor, and you can't mutate int objects after they've been created. So you just have to suck it up. For dict, in this case copy()+update() will work. But that's just luck. C code that inserts a new key into a dict shouldn't have to look for an overridden |
This comment has been minimized.
This comment has been minimized.
I don't believe this was ever explicitly outlined in the PEP (probably because we didn't get much pushback relative to other decisions Thinking out loud, if How do we feel about keeping the |
This comment has been minimized.
This comment has been minimized.
I still think it's a doubtful choice (and the PEP is clear that the code there is not exactly equivalent). Can you bring this up in the python-dev thread? So far you've convinced 0 out of 2 core devs -- but you still could get the Steering Council behind you. |
This comment has been minimized.
This comment has been minimized.
Sorry, one out of three. :-)
|
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
This happened right?
|
This comment has been minimized.
This comment has been minimized.
Yes, I commented in the new PEP thread: |
This comment has been minimized.
This comment has been minimized.
I am going to go ahead and remove the |
LGTM. Obviously let's wait until PEP 584 is accepted. |
This comment has been minimized.
This comment has been minimized.
Thanks for all of the feedback @gvanrossum and @serhiy-storchaka (especially for your insightful comments on the subclass issue). |
This comment has been minimized.
This comment has been minimized.
Guido just informed us that the Steering Council accepted his recommendation! |
eb8ac57
into
python:master
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Feb 25, 2020
@gvanrossum: Please replace |
brandtbucher commentedFeb 28, 2019
•
edited by bedevere-bot
https://bugs.python.org/issue36144