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

|= does not work as expected on TOMLDocument #331

Closed
5j9 opened this issue Feb 10, 2024 · 0 comments · Fixed by #334
Closed

|= does not work as expected on TOMLDocument #331

5j9 opened this issue Feb 10, 2024 · 0 comments · Fixed by #334
Assignees

Comments

@5j9
Copy link

5j9 commented Feb 10, 2024

I was expecting |= operator to work the same as .update method, because that's how Python dicts work, but |= on a TOMLDocument seems to have no effect:

from tomlkit import TOMLDocument

d1 = TOMLDocument()
d1['a'] = {'b': 'c'}
d2 = TOMLDocument()
d2['a'] = {'b': 'Z'}
d1['a'] |= d2['a']  # expected to be the same as d1['a'].update(d2['a']), but it's not

assert d1 == {'a': {'b': 'Z'}}, d1  # AssertionError: {'a': {'b': 'c'}}

Same code using a Python dict:

d1 = {'a': {'b': 'c'}}
d2 = {'a': {'b': 'Z'}}

d1['a'] |= d2['a']

assert d1 == {'a': {'b': 'Z'}}  # no error
@frostming frostming self-assigned this Feb 27, 2024
frostming added a commit that referenced this issue Feb 27, 2024
frostming added a commit that referenced this issue Feb 27, 2024
…ff-by: Frost Ming <[email protected]>

* fix: `|=` does not work as expected on TOMLDocument
Fixes #331

Signed-off-by: Frost Ming <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants