Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a += and + operator for dictionaries #14142

Open
dcbaker opened this issue Jan 15, 2025 · 0 comments
Open

Add a += and + operator for dictionaries #14142

dcbaker opened this issue Jan 15, 2025 · 0 comments
Milestone

Comments

@dcbaker
Copy link
Member

dcbaker commented Jan 15, 2025

Like for arrays, I'd imagine that if you wrote something like:

x = {'foo' : 1}
x += {'bar': 2}

that this would be equivalent to:

x = {'foo' : 1} + {'bar': 2}

The only question that remains is what to do with key collisions. There are two possibilities that seem acceptable to me:

  1. The RHS dict overrides the LHS
    Equivalent python
    d = d1.copy()
    d.update(d2)
    return d
  2. keys existing in both dicts is an error
@bonzini bonzini added this to the 1.8 milestone Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants