forked from Rust-related/RustPython
Add or, ror andior to defaultdict
This commit is contained in:
20
Lib/collections/_defaultdict.py
vendored
20
Lib/collections/_defaultdict.py
vendored
@@ -39,4 +39,24 @@ class defaultdict(dict):
|
||||
args = ()
|
||||
return type(self), args, None, None, iter(self.items())
|
||||
|
||||
def __or__(self, other):
|
||||
if not isinstance(other, dict):
|
||||
raise TypeError(f'unsupported operand type(s) for |: \'collections.{self.__class__.__qualname__}\' and \'{type(other).__qualname__}\'')
|
||||
|
||||
new = defaultdict(self.default_factory, self)
|
||||
new.update(other)
|
||||
return new
|
||||
|
||||
def __ror__(self, other):
|
||||
if not isinstance(other, dict):
|
||||
raise TypeError(f'unsupported operand type(s) for |: \'collections.{self.__class__.__qualname__}\' and \'{type(other).__qualname__}\'')
|
||||
|
||||
new = defaultdict(self.default_factory, other)
|
||||
new.update(self)
|
||||
return new
|
||||
|
||||
def __ior__(self, other):
|
||||
self.update(other)
|
||||
return self
|
||||
|
||||
defaultdict.__module__ = 'collections'
|
||||
|
||||
2
Lib/test/test_defaultdict.py
vendored
2
Lib/test/test_defaultdict.py
vendored
@@ -150,8 +150,6 @@ class TestDefaultDict(unittest.TestCase):
|
||||
o = pickle.loads(s)
|
||||
self.assertEqual(d, o)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_union(self):
|
||||
i = defaultdict(int, {1: 1, 2: 2})
|
||||
s = defaultdict(str, {0: "zero", 1: "one"})
|
||||
|
||||
Reference in New Issue
Block a user