Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions minfraud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import json
from typing import TYPE_CHECKING

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

def __hash__(self) -> int:
# This is not particularly efficient, but I don't expect it to be used much.
return hash(json.dumps(self.to_dict(), sort_keys=True))
Comment on lines +23 to +24
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new hash implementation using json.dumps with sort_keys is clear but may have performance implications if used frequently; consider caching the result if this method is expected to be called repeatedly.

Suggested change
# This is not particularly efficient, but I don't expect it to be used much.
return hash(json.dumps(self.to_dict(), sort_keys=True))
if not hasattr(self, "_cached_hash"):
self._cached_hash = hash(json.dumps(self.to_dict(), sort_keys=True))
return self._cached_hash

Copilot uses AI. Check for mistakes.

def to_dict(self) -> dict: # noqa: C901
"""Return a dict of the object suitable for serialization."""
result = {}
Expand Down Expand Up @@ -322,9 +327,9 @@ def __init__(
self,
domain: dict | None = None,
first_seen: str | None = None,
is_disposable: bool | None = None,
is_free: bool | None = None,
is_high_risk: bool | None = None,
is_disposable: bool | None = None, # noqa: FBT001
is_free: bool | None = None, # noqa: FBT001
is_high_risk: bool | None = None, # noqa: FBT001
) -> None:
"""Initialize an Email instance."""
self.domain = EmailDomain(**(domain or {}))
Expand Down Expand Up @@ -376,10 +381,10 @@ def __init__(
issuer: dict | None = None,
country: str | None = None,
brand: str | None = None,
is_business: bool | None = None,
is_issued_in_billing_address_country: bool | None = None,
is_prepaid: bool | None = None,
is_virtual: bool | None = None,
is_business: bool | None = None, # noqa: FBT001
is_issued_in_billing_address_country: bool | None = None, # noqa: FBT001
is_prepaid: bool | None = None, # noqa: FBT001
is_virtual: bool | None = None, # noqa: FBT001
type: str | None = None, # noqa: A002
) -> None:
"""Initialize a CreditCard instance."""
Expand Down
2 changes: 0 additions & 2 deletions minfraud/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ def _clean_domain(domain: str) -> str:

idx = domain.rfind(".")
if idx != -1:
# flake8: noqa: E203
tld = domain[idx + 1 :]
if typo_tld := _TYPO_TLDS.get(tld):
domain = domain[:idx] + "." + typo_tld
Expand All @@ -370,7 +369,6 @@ def _clean_email(address: str) -> tuple[str | None, str | None]:
if at_idx == -1:
return None, None

# flake8: noqa: E203
domain = _clean_domain(address[at_idx + 1 :])
local_part = address[:at_idx]

Expand Down
Loading
Loading