Skip to content

|= does not work as expected on TOMLDocument #331

Closed

Description

@5j9

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

Activity

  1. self-assigned this
    on Feb 27, 2024
  2. added a commit that references this issue on Feb 27, 2024
    fd694c1
  3. added a commit that references this issue on Feb 27, 2024
    0c2c30d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions