Repository: mahmoud/boltons

Issue:
Support in-place union for `dictutils.OrderedMultiDict`
Not sure if this is a feature request or bug since `OMD` inherits from `dict`.

Python `3.11.3`
Version `23.0.0`

```python
# union with a `dict`
In [2]: a = boltons.dictutils.OrderedMultiDict({'a': 1})

In [3]: a | {'c': 4}
Out[3]: {'a': 1, 'c': 4}

In [4]: a |= {'d': 5}

In [5]: a
Out[5]: OrderedMultiDict([('a', 1)])


# union with another `OMD`
In [10]: a = boltons.dictutils.OrderedMultiDict({'a': 1})

In [11]: a | boltons.dictutils.OrderedMultiDict({'c': 4})
Out[11]: {'a': 1, 'c': 4}

In [12]: a |= boltons.dictutils.OrderedMultiDict({'d': 5})

In [13]: a
Out[13]: OrderedMultiDict([('a', 1)])
```

`dict`'s behaviour
```python
In [6]: a = {'a': 1}

In [7]: a | {'c': 4}
Out[7]: {'a': 1, 'c': 4}

In [8]: a |= {'d': 5}

In [9]: a
Out[9]: {'a': 1, 'd': 5}
```

Discussion:
mahmoud: Looks great! Thanks!

Patch:
diff --git a/boltons/dictutils.py b/boltons/dictutils.py
index d74abb9..cc70d3c 100644
--- a/boltons/dictutils.py
+++ b/boltons/dictutils.py
@@ -386,6 +386,10 @@ class OrderedMultiDict(dict):
     def __ne__(self, other):
         return not (self == other)
 
+    def __ior__(self, other):
+        self.update(other)
+        return self
+
     def pop(self, k, default=_MISSING):
         """Remove all values under key *k*, returning the most-recently
         inserted value. Raises :exc:`KeyError` if the key is not


Test patch:
diff --git a/tests/test_dictutils.py b/tests/test_dictutils.py
index 076798b..20c431f 100644
--- a/tests/test_dictutils.py
+++ b/tests/test_dictutils.py
@@ -301,6 +301,19 @@ def test_setdefault():
     assert e_omd.popall(1, None) is None
     assert len(e_omd) == 0
 
+
+def test_ior():
+    omd_a = OMD(_ITEMSETS[1])
+    omd_b = OMD(_ITEMSETS[2])
+    omd_c = OMD(_ITEMSETS[1])
+
+    omd_a_id = id(omd_a)
+    omd_a |= omd_b
+    omd_c.update(omd_b)
+
+    assert omd_a_id == id(omd_a)
+    assert omd_a == omd_c
+
 ## END OMD TESTS
 
 import string