Skip to content

Commit 894b2c2

Browse files
committed
Run ruff's fixer
1 parent fb453e2 commit 894b2c2

File tree

11 files changed

+270
-134
lines changed

11 files changed

+270
-134
lines changed

docs/conf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# geoip2 documentation build configuration file, created by
54
# sphinx-quickstart on Tue Apr 9 13:34:57 2013.
@@ -12,8 +11,8 @@
1211
# All configuration values have a default; values that are commented out
1312
# serve to show the default.
1413

15-
import sys
1614
import os
15+
import sys
1716

1817
# If extensions (or modules to document with autodoc) are in another directory,
1918
# add these directories to sys.path here. If the directory is relative to the

examples/benchmark.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/python
2-
# -*- coding: utf-8 -*-
32

4-
from __future__ import print_function
53

64
import argparse
7-
import geoip2.database
85
import random
96
import socket
107
import struct
118
import timeit
129

10+
import geoip2.database
11+
1312
parser = argparse.ArgumentParser(description="Benchmark maxminddb.")
1413
parser.add_argument("--count", default=250000, type=int, help="number of lookups")
1514
parser.add_argument("--mode", default=0, type=int, help="reader mode to use")

geoip2/_internal.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
# pylint: disable=too-few-public-methods
44
from abc import ABCMeta
5-
from typing import Any
65

76

87
class Model(metaclass=ABCMeta):
98
"""Shared methods for MaxMind model classes"""
109

11-
def __eq__(self, other: Any) -> bool:
10+
def __eq__(self, other: object) -> bool:
1211
return isinstance(other, self.__class__) and self.to_dict() == other.to_dict()
1312

1413
def __ne__(self, other):

geoip2/database.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,41 @@
77

88
import inspect
99
import os
10-
from typing import Any, AnyStr, cast, IO, Optional, Sequence, Type, Union
10+
from collections.abc import Sequence
11+
from typing import IO, Any, AnyStr, Optional, Type, Union, cast
1112

1213
import maxminddb
13-
1414
from maxminddb import (
1515
MODE_AUTO,
16-
MODE_MMAP,
17-
MODE_MMAP_EXT,
16+
MODE_FD,
1817
MODE_FILE,
1918
MODE_MEMORY,
20-
MODE_FD,
19+
MODE_MMAP,
20+
MODE_MMAP_EXT,
2121
)
2222

2323
import geoip2
24-
import geoip2.models
2524
import geoip2.errors
26-
from geoip2.types import IPAddress
25+
import geoip2.models
2726
from geoip2.models import (
2827
ASN,
28+
ISP,
2929
AnonymousIP,
3030
City,
3131
ConnectionType,
3232
Country,
3333
Domain,
3434
Enterprise,
35-
ISP,
3635
)
36+
from geoip2.types import IPAddress
3737

3838
__all__ = [
3939
"MODE_AUTO",
40-
"MODE_MMAP",
41-
"MODE_MMAP_EXT",
40+
"MODE_FD",
4241
"MODE_FILE",
4342
"MODE_MEMORY",
44-
"MODE_FD",
43+
"MODE_MMAP",
44+
"MODE_MMAP_EXT",
4545
"Reader",
4646
]
4747

@@ -135,9 +135,9 @@ def country(self, ip_address: IPAddress) -> Country:
135135
:returns: :py:class:`geoip2.models.Country` object
136136
137137
"""
138-
139138
return cast(
140-
Country, self._model_for(geoip2.models.Country, "Country", ip_address)
139+
Country,
140+
self._model_for(geoip2.models.Country, "Country", ip_address),
141141
)
142142

143143
def city(self, ip_address: IPAddress) -> City:
@@ -161,7 +161,9 @@ def anonymous_ip(self, ip_address: IPAddress) -> AnonymousIP:
161161
return cast(
162162
AnonymousIP,
163163
self._flat_model_for(
164-
geoip2.models.AnonymousIP, "GeoIP2-Anonymous-IP", ip_address
164+
geoip2.models.AnonymousIP,
165+
"GeoIP2-Anonymous-IP",
166+
ip_address,
165167
),
166168
)
167169

@@ -174,7 +176,8 @@ def asn(self, ip_address: IPAddress) -> ASN:
174176
175177
"""
176178
return cast(
177-
ASN, self._flat_model_for(geoip2.models.ASN, "GeoLite2-ASN", ip_address)
179+
ASN,
180+
self._flat_model_for(geoip2.models.ASN, "GeoLite2-ASN", ip_address),
178181
)
179182

180183
def connection_type(self, ip_address: IPAddress) -> ConnectionType:
@@ -188,7 +191,9 @@ def connection_type(self, ip_address: IPAddress) -> ConnectionType:
188191
return cast(
189192
ConnectionType,
190193
self._flat_model_for(
191-
geoip2.models.ConnectionType, "GeoIP2-Connection-Type", ip_address
194+
geoip2.models.ConnectionType,
195+
"GeoIP2-Connection-Type",
196+
ip_address,
192197
),
193198
)
194199

@@ -227,7 +232,8 @@ def isp(self, ip_address: IPAddress) -> ISP:
227232
228233
"""
229234
return cast(
230-
ISP, self._flat_model_for(geoip2.models.ISP, "GeoIP2-ISP", ip_address)
235+
ISP,
236+
self._flat_model_for(geoip2.models.ISP, "GeoIP2-ISP", ip_address),
231237
)
232238

233239
def _get(self, database_type: str, ip_address: IPAddress) -> Any:
@@ -253,13 +259,20 @@ def _model_for(
253259
) -> Union[Country, Enterprise, City]:
254260
(record, prefix_len) = self._get(types, ip_address)
255261
return model_class(
256-
self._locales, ip_address=ip_address, prefix_len=prefix_len, **record
262+
self._locales,
263+
ip_address=ip_address,
264+
prefix_len=prefix_len,
265+
**record,
257266
)
258267

259268
def _flat_model_for(
260269
self,
261270
model_class: Union[
262-
Type[Domain], Type[ISP], Type[ConnectionType], Type[ASN], Type[AnonymousIP]
271+
Type[Domain],
272+
Type[ISP],
273+
Type[ConnectionType],
274+
Type[ASN],
275+
Type[AnonymousIP],
263276
],
264277
types: str,
265278
ip_address: IPAddress,
@@ -278,5 +291,4 @@ def metadata(
278291

279292
def close(self) -> None:
280293
"""Closes the GeoIP2 database."""
281-
282294
self._db_reader.close()

geoip2/errors.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def __init__(
5454
@property
5555
def network(self) -> Optional[Union[ipaddress.IPv4Network, ipaddress.IPv6Network]]:
5656
"""The network for the error"""
57-
5857
if self.ip_address is None or self._prefix_len is None:
5958
return None
6059
return ipaddress.ip_network(f"{self.ip_address}/{self._prefix_len}", False)

geoip2/models.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# pylint: disable=too-many-instance-attributes,too-few-public-methods,too-many-arguments
1515
import ipaddress
1616
from abc import ABCMeta
17-
from typing import Dict, List, Optional, Sequence, Union
17+
from collections.abc import Sequence
18+
from typing import Dict, List, Optional, Union
1819

1920
import geoip2.records
2021
from geoip2._internal import Model
@@ -94,10 +95,12 @@ def __init__(
9495
self.continent = geoip2.records.Continent(locales, **(continent or {}))
9596
self.country = geoip2.records.Country(locales, **(country or {}))
9697
self.registered_country = geoip2.records.Country(
97-
locales, **(registered_country or {})
98+
locales,
99+
**(registered_country or {}),
98100
)
99101
self.represented_country = geoip2.records.RepresentedCountry(
100-
locales, **(represented_country or {})
102+
locales,
103+
**(represented_country or {}),
101104
)
102105

103106
self.maxmind = geoip2.records.MaxMind(**(maxmind or {}))
@@ -112,8 +115,8 @@ def __init__(
112115

113116
def __repr__(self) -> str:
114117
return (
115-
f"{self.__module__}.{self.__class__.__name__}({repr(self._locales)}, "
116-
f"{', '.join(f'{k}={repr(v)}' for k, v in self.to_dict().items())})"
118+
f"{self.__module__}.{self.__class__.__name__}({self._locales!r}, "
119+
f"{', '.join(f'{k}={v!r}' for k, v in self.to_dict().items())})"
117120
)
118121

119122

@@ -387,15 +390,16 @@ def __repr__(self) -> str:
387390
f"{self.__module__}.{self.__class__.__name__}("
388391
+ repr(str(self._ip_address))
389392
+ ", "
390-
+ ", ".join(f"{k}={repr(v)}" for k, v in d.items())
393+
+ ", ".join(f"{k}={v!r}" for k, v in d.items())
391394
+ ")"
392395
)
393396

394397
@property
395398
def ip_address(self):
396399
"""The IP address for the record"""
397400
if not isinstance(
398-
self._ip_address, (ipaddress.IPv4Address, ipaddress.IPv6Address)
401+
self._ip_address,
402+
(ipaddress.IPv4Address, ipaddress.IPv6Address),
399403
):
400404
self._ip_address = ipaddress.ip_address(self._ip_address)
401405
return self._ip_address

geoip2/records.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
# pylint:disable=R0903
1313
from abc import ABCMeta
14-
from typing import Dict, Optional, Type, Sequence, Union
14+
from collections.abc import Sequence
15+
from typing import Dict, Optional, Type, Union
1516

1617
from geoip2._internal import Model
1718

@@ -113,7 +114,6 @@ class Continent(PlaceRecord):
113114
114115
Attributes:
115116
116-
117117
.. attribute:: code
118118
119119
A two character continent code like "NA" (North America)
@@ -167,7 +167,6 @@ class Country(PlaceRecord):
167167
168168
Attributes:
169169
170-
171170
.. attribute:: confidence
172171
173172
A value from 0-100 indicating MaxMind's confidence that
@@ -244,7 +243,6 @@ class RepresentedCountry(Country):
244243
245244
Attributes:
246245
247-
248246
.. attribute:: confidence
249247
250248
A value from 0-100 indicating MaxMind's confidence that
@@ -470,7 +468,11 @@ class Postal(Record):
470468
confidence: Optional[int]
471469

472470
def __init__(
473-
self, *, code: Optional[str] = None, confidence: Optional[int] = None, **_
471+
self,
472+
*,
473+
code: Optional[str] = None,
474+
confidence: Optional[int] = None,
475+
**_,
474476
) -> None:
475477
self.code = code
476478
self.confidence = confidence
@@ -556,7 +558,9 @@ class Subdivisions(tuple):
556558
"""
557559

558560
def __new__(
559-
cls: Type["Subdivisions"], locales: Optional[Sequence[str]], *subdivisions
561+
cls: Type["Subdivisions"],
562+
locales: Optional[Sequence[str]],
563+
*subdivisions,
560564
) -> "Subdivisions":
561565
subobjs = tuple(Subdivision(locales, **x) for x in subdivisions)
562566
obj = super().__new__(cls, subobjs) # type: ignore
@@ -923,7 +927,8 @@ def __init__(
923927
def ip_address(self):
924928
"""The IP address for the record"""
925929
if not isinstance(
926-
self._ip_address, (ipaddress.IPv4Address, ipaddress.IPv6Address)
930+
self._ip_address,
931+
(ipaddress.IPv4Address, ipaddress.IPv6Address),
927932
):
928933
self._ip_address = ipaddress.ip_address(self._ip_address)
929934
return self._ip_address

0 commit comments

Comments
 (0)