Skip to content

Commit a60b063

Browse files
committed
Implement __hash__ in models
Ruff wants this whenever __eq__ is implemented.
1 parent b56c345 commit a60b063

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

minfraud/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import json
56
from typing import TYPE_CHECKING
67

78
import geoip2.models
@@ -18,6 +19,10 @@ def __eq__(self, other: object) -> bool:
1819
def __ne__(self, other: object) -> bool:
1920
return not self.__eq__(other)
2021

22+
def __hash__(self) -> int:
23+
# This is not particularly efficient, but I don't expect it to be used much.
24+
return hash(json.dumps(self.to_dict(), sort_keys=True))
25+
2126
def to_dict(self) -> dict: # noqa: C901
2227
"""Return a dict of the object suitable for serialization."""
2328
result = {}

0 commit comments

Comments
 (0)