Skip to content

Commit 0a56acf

Browse files
committed
Convert methods to static methods
And switch a complicated yet mislead type signature to Any.
1 parent 319a60f commit 0a56acf

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

geoip2/webservice.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"""
2727

2828
import ipaddress
29-
from typing import cast, Dict, List, Optional, Type, Union
29+
from typing import Any, cast, List, Optional, Type, Union
3030

3131
import requests
3232
from requests.models import Response
@@ -173,24 +173,15 @@ def _response_for(
173173
body = self._handle_success(response, uri)
174174
return model_class(body, locales=self._locales)
175175

176-
def _user_agent(self) -> str:
176+
@staticmethod
177+
def _user_agent() -> str:
177178
return "GeoIP2 Python Client v%s (%s)" % (
178179
geoip2.__version__,
179180
default_user_agent(),
180181
)
181182

182-
def _handle_success(
183-
self, response: Response, uri: str
184-
) -> Dict[
185-
str,
186-
Union[
187-
Dict[str, Union[str, int, Dict[str, str]]],
188-
Dict[str, int],
189-
Dict[str, Union[int, bool, str, Dict[str, str]]],
190-
Dict[str, Union[int, float, str]],
191-
Dict[str, str],
192-
],
193-
]:
183+
@staticmethod
184+
def _handle_success(response: Response, uri: str) -> Any:
194185
try:
195186
return response.json()
196187
except ValueError as ex:
@@ -247,8 +238,9 @@ def _exception_for_4xx_status(
247238
uri,
248239
)
249240

241+
@staticmethod
250242
def _exception_for_web_service_error(
251-
self, message: str, code: str, status: int, uri: str
243+
message: str, code: str, status: int, uri: str
252244
) -> Union[
253245
AuthenticationError,
254246
AddressNotFoundError,
@@ -274,14 +266,16 @@ def _exception_for_web_service_error(
274266

275267
return InvalidRequestError(message, code, status, uri)
276268

277-
def _exception_for_5xx_status(self, status: int, uri: str) -> HTTPError:
269+
@staticmethod
270+
def _exception_for_5xx_status(status: int, uri: str) -> HTTPError:
278271
return HTTPError(
279272
"Received a server error (%(status)i) for " "%(uri)s" % locals(),
280273
status,
281274
uri,
282275
)
283276

284-
def _exception_for_non_200_status(self, status: int, uri: str) -> HTTPError:
277+
@staticmethod
278+
def _exception_for_non_200_status(status: int, uri: str) -> HTTPError:
285279
return HTTPError(
286280
"Received a very surprising HTTP status "
287281
"(%(status)i) for %(uri)s" % locals(),

pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[MESSAGES CONTROL]
2-
disable=C0330,R0201,R0205,W0105
2+
disable=C0330
33

44
[BASIC]
55

0 commit comments

Comments
 (0)