Skip to content
14 changes: 14 additions & 0 deletions src/xmmutablemap/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ def __len__(self) -> int:
"""
return len(self._data)

def __eq__(self, other: object) -> bool:
"""Return whether two mappings contain the same items."""
if isinstance(other, ImmutableMap):
return self._data == other._data
if isinstance(other, dict):
return self._data = other
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
if isinstance(other, Mapping):
return self._data == dict(other.items())
return NotImplemented
Comment thread
nstarman marked this conversation as resolved.

Comment thread
nstarman marked this conversation as resolved.
def __hash__(self) -> int:
"""Return an order-insensitive hash based on the mapping contents."""
return hash(frozenset(self._data.items()))

# ===========================================
# Mapping Protocol

Expand Down
Loading