77"""
88
99import json
10- from typing import Any , cast , Dict , Optional , Tuple , Type , Union
10+ from functools import partial
11+ from typing import Any , Callable , cast , Dict , Optional , Sequence , Union
1112
1213import aiohttp
1314import aiohttp .http
3940class BaseClient :
4041 _account_id : str
4142 _license_key : str
42- _locales : Tuple [str , ... ]
43+ _locales : Sequence [str ]
4344 _timeout : float
4445
4546 _score_uri : str
@@ -52,7 +53,7 @@ def __init__(
5253 account_id : int ,
5354 license_key : str ,
5455 host : str = "minfraud.maxmind.com" ,
55- locales : Tuple [str , ... ] = ("en" ,),
56+ locales : Sequence [str ] = ("en" ,),
5657 timeout : float = 60 ,
5758 ) -> None :
5859 self ._locales = locales
@@ -69,7 +70,7 @@ def _handle_success(
6970 self ,
7071 raw_body : str ,
7172 uri : str ,
72- model_class : Union [ Type [ Factors ], Type [ Score ], Type [ Insights ]] ,
73+ model_class : Callable ,
7374 ) -> Union [Score , Factors , Insights ]:
7475 """Handle successful response."""
7576 try :
@@ -81,8 +82,6 @@ def _handle_success(
8182 200 ,
8283 uri ,
8384 ) from ex
84- if "ip_address" in decoded_body :
85- decoded_body ["ip_address" ]["locales" ] = self ._locales
8685 return model_class (** decoded_body ) # type: ignore
8786
8887 def _exception_for_error (
@@ -210,7 +209,7 @@ def __init__(
210209 account_id : int ,
211210 license_key : str ,
212211 host : str = "minfraud.maxmind.com" ,
213- locales : Tuple [str , ... ] = ("en" ,),
212+ locales : Sequence [str ] = ("en" ,),
214213 timeout : float = 60 ,
215214 proxy : Optional [str ] = None ,
216215 ) -> None :
@@ -269,7 +268,7 @@ async def factors(
269268 Factors ,
270269 await self ._response_for (
271270 self ._factors_uri ,
272- Factors ,
271+ partial ( Factors , self . _locales ) ,
273272 transaction ,
274273 validate ,
275274 hash_email ,
@@ -308,7 +307,7 @@ async def insights(
308307 Insights ,
309308 await self ._response_for (
310309 self ._insights_uri ,
311- Insights ,
310+ partial ( Insights , self . _locales ) ,
312311 transaction ,
313312 validate ,
314313 hash_email ,
@@ -387,7 +386,7 @@ async def report(
387386 async def _response_for (
388387 self ,
389388 uri : str ,
390- model_class : Union [ Type [ Factors ], Type [ Score ], Type [ Insights ]] ,
389+ model_class : Callable ,
391390 request : Dict [str , Any ],
392391 validate : bool ,
393392 hash_email : bool ,
@@ -445,7 +444,7 @@ def __init__(
445444 account_id : int ,
446445 license_key : str ,
447446 host : str = "minfraud.maxmind.com" ,
448- locales : Tuple [str , ... ] = ("en" ,),
447+ locales : Sequence [str ] = ("en" ,),
449448 timeout : float = 60 ,
450449 proxy : Optional [str ] = None ,
451450 ) -> None :
@@ -518,7 +517,7 @@ def factors(
518517 Factors ,
519518 self ._response_for (
520519 self ._factors_uri ,
521- Factors ,
520+ partial ( Factors , self . _locales ) ,
522521 transaction ,
523522 validate ,
524523 hash_email ,
@@ -557,7 +556,7 @@ def insights(
557556 Insights ,
558557 self ._response_for (
559558 self ._insights_uri ,
560- Insights ,
559+ partial ( Insights , self . _locales ) ,
561560 transaction ,
562561 validate ,
563562 hash_email ,
@@ -634,7 +633,7 @@ def report(self, report: Dict[str, Optional[str]], validate: bool = True) -> Non
634633 def _response_for (
635634 self ,
636635 uri : str ,
637- model_class : Union [ Type [ Factors ], Type [ Score ], Type [ Insights ]] ,
636+ model_class : Callable ,
638637 request : Dict [str , Any ],
639638 validate : bool ,
640639 hash_email : bool ,
0 commit comments