|
8 | 8 |
|
9 | 9 | # pylint:disable=too-many-lines,too-many-instance-attributes,too-many-locals |
10 | 10 | from collections.abc import Sequence |
11 | | -from typing import Optional |
| 11 | +from typing import Any, Optional |
12 | 12 |
|
13 | 13 | import geoip2.models |
14 | 14 | import geoip2.records |
15 | | -from geoip2.mixins import SimpleEquality |
16 | 15 |
|
17 | 16 |
|
18 | | -class _Serializable(SimpleEquality): |
| 17 | +class _Serializable: |
| 18 | + def __eq__(self, other: object) -> bool: |
| 19 | + return isinstance(other, self.__class__) and self.to_dict() == other.to_dict() |
| 20 | + |
| 21 | + def __ne__(self, other) -> bool: |
| 22 | + return not self.__eq__(other) |
| 23 | + |
19 | 24 | def to_dict(self) -> dict: |
20 | 25 | """Returns a dict of the object suitable for serialization.""" |
21 | 26 | result = {} |
22 | 27 | for key, value in self.__dict__.items(): |
23 | 28 | if hasattr(value, "to_dict") and callable(value.to_dict): |
24 | 29 | if d := value.to_dict(): |
25 | 30 | result[key] = d |
26 | | - elif hasattr(value, "raw"): |
27 | | - # geoip2 uses "raw" for historical reasons |
28 | | - if d := value.raw: |
29 | | - result[key] = d |
30 | 31 | elif isinstance(value, list): |
31 | 32 | ls = [] |
32 | 33 | for e in value: |
@@ -221,7 +222,7 @@ def __init__( |
221 | 222 | if risk_reasons is not None: |
222 | 223 | kwargs["risk_reasons"] = risk_reasons |
223 | 224 |
|
224 | | - super().__init__(kwargs, locales=list(locales or [])) |
| 225 | + super().__init__(locales, **kwargs) |
225 | 226 | self.location = GeoIP2Location(**(location or {})) |
226 | 227 | self.risk = risk |
227 | 228 | self.risk_reasons = [IPRiskReason(**x) for x in risk_reasons or []] |
|
0 commit comments