Skip to content

Commit

Permalink
fix: |= does not work as expected on TOMLDocumentFixes #331Signed-o…
Browse files Browse the repository at this point in the history
…ff-by: Frost Ming <me@frostming.com>

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

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Feb 27, 2024
1 parent a3ed6a1 commit 0c2c30d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Support `|` and `|=` operator for tables, and support `+` and `+=` operator for arrays. ([#331](https://github.com/sdispater/tomlkit/issues/331))

## [0.12.3] - 2023-11-15

### Fixed
Expand Down
20 changes: 19 additions & 1 deletion tomlkit/_types.py
Expand Up @@ -43,9 +43,27 @@ def _new(self: WT, value: Any) -> WT:
class _CustomList(MutableSequence, list):
"""Adds MutableSequence mixin while pretending to be a builtin list"""

def __add__(self, other):
new_list = self.copy()
new_list.extend(other)
return new_list

def __iadd__(self, other):
self.extend(other)
return self

class _CustomDict(MutableMapping, dict):
"""Adds MutableMapping mixin while pretending to be a builtin dict"""

def __or__(self, other):
new_dict = self.copy()
new_dict.update(other)
return new_dict

def __ior__(self, other):
self.update(other)
return self

class _CustomInt(Integral, int):
"""Adds Integral mixin while pretending to be a builtin int"""

Expand All @@ -54,7 +72,7 @@ class _CustomFloat(Real, float):


def wrap_method(
original_method: Callable[Concatenate[WT, P], Any]
original_method: Callable[Concatenate[WT, P], Any],
) -> Callable[Concatenate[WT, P], Any]:
def wrapper(self: WT, *args: P.args, **kwargs: P.kwargs) -> Any:
result = original_method(self, *args, **kwargs)
Expand Down

0 comments on commit 0c2c30d

Please sign in to comment.