8000 Add __hash__ method for models · maxmind/GeoIP2-python@34e607c · GitHub
[go: up one dir, main page]

Skip to content

Commit 34e607c

Browse files
committed
Add __hash__ method for models
1 parent d5ed14e commit 34e607c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

geoip2/_internal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Internal utilities."""
22

3+
import json
34
from abc import ABCMeta
45

56

@@ -12,6 +13,10 @@ def __eq__(self, other: object) -> bool:
1213
def __ne__(self, other: object) -> bool:
1314
return not self.__eq__(other)
1415

16+
def __hash__(self) -> int:
17+
# This is not particularly efficient, but I don't expect it to be used much.
18+
return hash(json.dumps(self.to_dict(), sort_keys=True))
19+
1520
def to_dict(self) -> dict: # noqa: C901, PLR0912
1621
"""Return a dict of the object suitable for serialization."""
1722
result = {}

0 commit comments

Comments
 (0)
0