Skip to content

Commit 0c2c30d

Browse files
authored
fix: |= does not work as expected on TOMLDocumentFixes #331Signed-off-by: Frost Ming <[email protected]>
* fix: `|=` does not work as expected on TOMLDocument Fixes #331 Signed-off-by: Frost Ming <[email protected]>
1 parent a3ed6a1 commit 0c2c30d

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Support `|` and `|=` operator for tables, and support `+` and `+=` operator for arrays. ([#331](https://github.com/sdispater/tomlkit/issues/331))
8+
59
## [0.12.3] - 2023-11-15
610

711
### Fixed

tomlkit/_types.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,27 @@ def _new(self: WT, value: Any) -> WT:
4343
class _CustomList(MutableSequence, list):
4444
"""Adds MutableSequence mixin while pretending to be a builtin list"""
4545

46+
def __add__(self, other):
47+
new_list = self.copy()
48+
new_list.extend(other)
49+
return new_list
50+
51+
def __iadd__(self, other):
52+
self.extend(other)
53+
return self
54+
4655
class _CustomDict(MutableMapping, dict):
4756
"""Adds MutableMapping mixin while pretending to be a builtin dict"""
4857

58+
def __or__(self, other):
59+
new_dict = self.copy()
60+
new_dict.update(other)
61+
return new_dict
62+
63+
def __ior__(self, other):
64+
self.update(other)
65+
return self
66+
4967
class _CustomInt(Integral, int):
5068
"""Adds Integral mixin while pretending to be a builtin int"""
5169

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

5573

5674
def wrap_method(
57-
original_method: Callable[Concatenate[WT, P], Any]
75+
original_method: Callable[Concatenate[WT, P], Any],
5876
) -> Callable[Concatenate[WT, P], Any]:
5977
def wrapper(self: WT, *args: P.args, **kwargs: P.kwargs) -> Any:
6078
result = original_method(self, *args, **kwargs)

0 commit comments

Comments
 (0)