Fix union with assignment operator inconsistent results (compared to `dict`). #334
This commit is contained in:
parent
a80201e975
commit
8b05daad7e
|
@ -58,6 +58,11 @@ class BaseDict(dict):
|
||||||
return self._dict[key]
|
return self._dict[key]
|
||||||
return super().__getitem__(key)
|
return super().__getitem__(key)
|
||||||
|
|
||||||
|
def __ior__(self, other):
|
||||||
|
if self._pointer:
|
||||||
|
return self._dict.__ior__(other)
|
||||||
|
return super().__ior__(other)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
if self._pointer:
|
if self._pointer:
|
||||||
return iter(self._dict)
|
return iter(self._dict)
|
||||||
|
@ -68,6 +73,11 @@ class BaseDict(dict):
|
||||||
return len(self._dict)
|
return len(self._dict)
|
||||||
return super().__len__()
|
return super().__len__()
|
||||||
|
|
||||||
|
def __or__(self, other):
|
||||||
|
if self._pointer:
|
||||||
|
return self._dict.__or__(other)
|
||||||
|
return super().__or__(other)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self._pointer:
|
if self._pointer:
|
||||||
return repr(self._dict)
|
return repr(self._dict)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from benedict import benedict
|
||||||
|
|
||||||
|
|
||||||
|
class github_issue_0334_test_case(unittest.TestCase):
|
||||||
|
"""
|
||||||
|
This class describes a github issue 0334 test case.
|
||||||
|
https://github.com/fabiocaccamo/python-benedict/issues/294
|
||||||
|
|
||||||
|
To run this specific test:
|
||||||
|
- Run python -m unittest tests.github.test_issue_0334
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_union_with_assignement_operator(self):
|
||||||
|
a = {"a": "a", "b": "b"}
|
||||||
|
b = {"b": "b", "c": "c"}
|
||||||
|
|
||||||
|
ab = benedict(a.copy())
|
||||||
|
bb = benedict(b.copy())
|
||||||
|
self.assertEqual(a | b, ab | bb)
|
||||||
|
|
||||||
|
a |= b.copy()
|
||||||
|
ab |= bb.copy()
|
||||||
|
self.assertEqual(a, ab)
|
Loading…
Reference in New Issue