Skip to content

Commit 4b9d0e4

Browse files
committed
Ignore and fix misc lints
1 parent f99a254 commit 4b9d0e4

File tree

8 files changed

+66
-50
lines changed

8 files changed

+66
-50
lines changed

examples/benchmark.py

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import timeit
1010

1111
import geoip2.database
12+
import geoip2.errors
1213

1314
parser = argparse.ArgumentParser(description="Benchmark maxminddb.")
1415
parser.add_argument("--count", default=250000, type=int, help="number of lookups")
@@ -33,4 +34,4 @@ def lookup_ip_address() -> None:
3334
number=args.count,
3435
)
3536

36-
print(args.count / elapsed, "lookups per second")
37+
print(args.count / elapsed, "lookups per second") # noqa: T201

geoip2/_internal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from abc import ABCMeta
55

66

7-
class Model(metaclass=ABCMeta):
7+
class Model(metaclass=ABCMeta): # noqa: B024
88
"""Shared methods for MaxMind model classes."""
99

1010
def __eq__(self, other: object) -> bool:
@@ -14,7 +14,7 @@ def __ne__(self, other: object) -> bool:
1414
return not self.__eq__(other)
1515

1616
# pylint: disable=too-many-branches
17-
def to_dict(self) -> dict:
17+
def to_dict(self) -> dict: # noqa: C901, PLR0912
1818
"""Return a dict of the object suitable for serialization."""
1919
result = {}
2020
for key, value in self.__dict__.items():

geoip2/database.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313
MODE_MEMORY,
1414
MODE_MMAP,
1515
MODE_MMAP_EXT,
16+
InvalidDatabaseError,
1617
)
1718

18-
from maxminddb import InvalidDatabaseError
19-
2019
import geoip2
2120
import geoip2.errors
2221
import geoip2.models

geoip2/records.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(
176176
iso_code: str | None = None,
177177
names: dict[str, str] | None = None,
178178
# pylint:disable=redefined-builtin
179-
type: str | None = None,
179+
type: str | None = None, # noqa: A002
180180
**_,
181181
) -> None:
182182
self.type = type
@@ -333,7 +333,7 @@ def __init__(
333333
super().__init__(locales, names)
334334

335335

336-
class Subdivisions(tuple):
336+
class Subdivisions(tuple): # noqa: SLOT001
337337
"""A tuple-like collection of subdivisions associated with an IP address.
338338
339339
This class contains the subdivisions of the country associated with the
@@ -345,8 +345,6 @@ class Subdivisions(tuple):
345345
This attribute is returned by ``city``, ``enterprise``, and ``insights``.
346346
"""
347347

348-
__slots__ = ("_locales",)
349-
350348
def __new__(
351349
cls: type[Self],
352350
locales: Sequence[str] | None,

geoip2/webservice.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,10 @@ def _exception_for_4xx_status(
149149
decoded_body = json.loads(body)
150150
except ValueError as ex:
151151
return HTTPError(
152-
f"Received a {status} error for {uri} but it did not include "
153-
+ "the expected JSON body: "
154-
+ ", ".join(ex.args),
152+
(
153+
f"Received a {status} error for {uri} but it did not include "
154+
f"the expected JSON body: { ", ".join(ex.args) }"
155+
),
155156
status,
156157
uri,
157158
body,
@@ -284,7 +285,7 @@ class AsyncClient(BaseClient):
284285
_existing_session: aiohttp.ClientSession
285286
_proxy: str | None
286287

287-
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
288+
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments # noqa: PLR0913
288289
self,
289290
account_id: int,
290291
license_key: str,
@@ -454,7 +455,7 @@ class Client(BaseClient):
454455
_session: requests.Session
455456
_proxies: dict[str, str] | None
456457

457-
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments
458+
def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments # noqa: PLR0913
458459
self,
459460
account_id: int,
460461
license_key: str,

tests/database_test.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#!/usr/bin/env python
2-
3-
41
import datetime
52
import ipaddress
63
import sys
@@ -47,7 +44,7 @@ def test_unknown_address_network(self) -> None:
4744
self.fail("Expected AddressNotFoundError")
4845
except geoip2.errors.AddressNotFoundError as e:
4946
self.assertEqual(e.network, ipaddress.ip_network("10.0.0.0/8"))
50-
except Exception as e:
47+
except Exception as e: # noqa: BLE001
5148
self.fail(f"Expected AddressNotFoundError, got {type(e)}: {e!s}")
5249
finally:
5350
reader.close()
@@ -130,7 +127,11 @@ def test_asn(self) -> None:
130127
ip_address = "1.128.0.0"
131128
record = reader.asn(ip_address)
132129

133-
self.assertEqual(record, eval(repr(record)), "ASN repr can be eval'd")
130+
self.assertEqual(
131+
record,
132+
eval(repr(record)), # noqa: S307
133+
"ASN repr can be eval'd",
134+
)
134135

135136
self.assertEqual(record.autonomous_system_number, 1221)
136137
self.assertEqual(record.autonomous_system_organization, "Telstra Pty Ltd")
@@ -178,7 +179,7 @@ def test_connection_type(self) -> None:
178179

179180
self.assertEqual(
180181
record,
181-
eval(repr(record)),
182+
eval(repr(record)), # noqa: S307
182183
"ConnectionType repr can be eval'd",
183184
)
184185

@@ -218,7 +219,11 @@ def test_domain(self) -> None:
218219
ip_address = "1.2.0.0"
219220
record = reader.domain(ip_address)
220221

221-
self.assertEqual(record, eval(repr(record)), "Domain repr can be eval'd")
222+
self.assertEqual(
223+
record,
224+
eval(repr(record)), # noqa: S307
225+
"Domain repr can be eval'd",
226+
)
222227

223228
self.assertEqual(record.domain, "maxmind.com")
224229
self.assertEqual(record.ip_address, ipaddress.ip_address(ip_address))
@@ -266,7 +271,11 @@ def test_isp(self) -> None:
266271
) as reader:
267272
ip_address = "1.128.0.0"
268273
record = reader.isp(ip_address)
269-
self.assertEqual(record, eval(repr(record)), "ISP repr can be eval'd")
274+
self.assertEqual(
275+
record,
276+
eval(repr(record)), # noqa: S307
277+
"ISP repr can be eval'd",
278+
)
270279

271280
self.assertEqual(record.autonomous_system_number, 1221)
272281
self.assertEqual(record.autonomous_system_organization, "Telstra Pty Ltd")

tests/models_test.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ def test_insights_full(self) -> None:
194194
"Insights str representation looks reasonable",
195195
)
196196

197-
self.assertEqual(model, eval(repr(model)), "Insights repr can be eval'd")
197+
self.assertEqual(
198+
model,
199+
eval(repr(model)), # noqa: S307
200+
"Insights repr can be eval'd",
201+
)
198202

199203
self.assertRegex(
200204
str(model.location),
@@ -204,23 +208,29 @@ def test_insights_full(self) -> None:
204208

205209
self.assertEqual(
206210
model.location,
207-
eval(repr(model.location)),
211+
eval(repr(model.location)), # noqa: S307
208212
"Location repr can be eval'd",
209213
)
210214

211-
self.assertIs(model.country.is_in_european_union, False)
212-
self.assertIs(model.registered_country.is_in_european_union, False)
213-
self.assertIs(model.represented_country.is_in_european_union, True)
215+
self.assertIs(model.country.is_in_european_union, False) # noqa: FBT003
216+
self.assertIs(
217+
model.registered_country.is_in_european_union,
218+
False, # noqa: FBT003
219+
)
220+
self.assertIs(
221+
model.represented_country.is_in_european_union,
222+
True, # noqa: FBT003
223+
)
214224

215-
self.assertIs(model.traits.is_anonymous, True)
216-
self.assertIs(model.traits.is_anonymous_proxy, True)
217-
self.assertIs(model.traits.is_anonymous_vpn, True)
218-
self.assertIs(model.traits.is_anycast, True)
219-
self.assertIs(model.traits.is_hosting_provider, True)
220-
self.assertIs(model.traits.is_public_proxy, True)
221-
self.assertIs(model.traits.is_residential_proxy, True)
222-
self.assertIs(model.traits.is_satellite_provider, True)
223-
self.assertIs(model.traits.is_tor_exit_node, True)
225+
self.assertIs(model.traits.is_anonymous, True) # noqa: FBT003
226+
self.assertIs(model.traits.is_anonymous_proxy, True) # noqa: FBT003
227+
self.assertIs(model.traits.is_anonymous_vpn, True) # noqa: FBT003
228+
self.assertIs(model.traits.is_anycast, True) # noqa: FBT003
229+
self.assertIs(model.traits.is_hosting_provider, True) # noqa: FBT003
230+
self.assertIs(model.traits.is_public_proxy, True) # noqa: FBT003
231+
self.assertIs(model.traits.is_residential_proxy, True) # noqa: FBT003
232+
self.assertIs(model.traits.is_satellite_provider, True) # noqa: FBT003
233+
self.assertIs(model.traits.is_tor_exit_node, True) # noqa: FBT003
224234
self.assertEqual(model.traits.user_count, 2)
225235
self.assertEqual(model.traits.static_ip_score, 1.3)
226236

@@ -433,9 +443,9 @@ def test_unknown_keys(self) -> None:
433443
unk_base={"blah": 1},
434444
)
435445
with self.assertRaises(AttributeError):
436-
model.unk_base # type: ignore
446+
model.unk_base # type: ignore[attr-defined] # noqa: B018
437447
with self.assertRaises(AttributeError):
438-
model.traits.invalid # type: ignore
448+
model.traits.invalid # type: ignore[attr-defined] # noqa: B018
439449
self.assertEqual(
440450
model.traits.ip_address,
441451
ipaddress.ip_address("1.2.3.4"),

tests/webservice_test.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python
2-
31
from __future__ import annotations
42

53
import asyncio
@@ -99,7 +97,7 @@ def test_country_ok(self) -> None:
9997
self.assertEqual(country.country.geoname_id, 1, "country geoname_id is 1")
10098
self.assertIs(
10199
country.country.is_in_european_union,
102-
False,
100+
False, # noqa: FBT003
103101
"country is_in_european_union is False",
104102
)
105103
self.assertEqual(country.country.iso_code, "US", "country iso_code is US")
@@ -120,7 +118,7 @@ def test_country_ok(self) -> None:
120118
)
121119
self.assertIs(
122120
country.registered_country.is_in_european_union,
123-
True,
121+
True, # noqa: FBT003
124122
"registered_country is_in_european_union is True",
125123
)
126124
self.assertEqual(
@@ -273,10 +271,10 @@ def test_account_id_required(self) -> None:
273271
def test_user_id_required(self) -> None:
274272
self._test_error(401, "USER_ID_REQUIRED", AuthenticationError)
275273

276-
def test_account_id_unkown(self) -> None:
274+
def test_account_id_unknown(self) -> None:
277275
self._test_error(401, "ACCOUNT_ID_UNKNOWN", AuthenticationError)
278276

279-
def test_user_id_unkown(self) -> None:
277+
def test_user_id_unknown(self) -> None:
280278
self._test_error(401, "USER_ID_UNKNOWN", AuthenticationError)
281279

282280
def test_out_of_queries_error(self) -> None:
@@ -386,11 +384,11 @@ def test_insights_ok(self) -> None:
386384
self.assertEqual(insights.traits.user_count, 2, "user_count is 2")
387385

388386
def test_named_constructor_args(self) -> None:
389-
id = 47
387+
account_id = 47
390388
key = "1234567890ab"
391-
client = self.client_class(id, key)
392-
self.assertEqual(client._account_id, str(id))
393-
self.assertEqual(client._license_key, key)
389+
client = self.client_class(account_id, key)
390+
self.assertEqual(client._account_id, str(account_id)) # noqa: SLF001
391+
self.assertEqual(client._license_key, key) # noqa: SLF001
394392

395393
def test_missing_constructor_args(self) -> None:
396394
with self.assertRaises(TypeError):
@@ -406,7 +404,7 @@ class TestClient(TestBaseClient):
406404
def setUp(self) -> None:
407405
self.client_class = Client
408406
self.client = Client(42, "abcdef123456")
409-
self.client._base_uri = self.httpserver.url_for("/geoip/v2.1")
407+
self.client._base_uri = self.httpserver.url_for("/geoip/v2.1") # noqa: SLF001
410408
self.maxDiff = 20_000
411409

412410
def run_client(self, v): # noqa: ANN001
@@ -420,7 +418,7 @@ def setUp(self) -> None:
420418
self._loop = asyncio.new_event_loop()
421419
self.client_class = AsyncClient
422420
self.client = AsyncClient(42, "abcdef123456")
423-
self.client._base_uri = self.httpserver.url_for("/geoip/v2.1")
421+
self.client._base_uri = self.httpserver.url_for("/geoip/v2.1") # noqa: SLF001
424422
self.maxDiff = 20_000
425423

426424
def tearDown(self) -> None:

0 commit comments

Comments
 (0)