Skip to content

Commit

Permalink
Require record arguments to be keyword arguments
Browse files Browse the repository at this point in the history
This makes it easier to maintain going forward.
  • Loading branch information
oschwald committed Jan 22, 2025
1 parent 79ca31d commit c84b047
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ History
* BREAKING: The ``raw`` attribute on the model classes has been replaced
with a ``to_dict()`` method. This can be used to get a representation of
the object that is suitable for serialization.
* BREAKING: The record classes now require all arguments other than ``locales``
to be keyword arguments.
* BREAKING: ``geoip2.mixins`` has been made internal. This normally would not
have been used by external code.
* IMPORTANT: Python 3.9 or greater is required. If you are using an older
Expand Down
32 changes: 22 additions & 10 deletions geoip2/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class PlaceRecord(Record, metaclass=ABCMeta):

def __init__(
self,
locales: Optional[Sequence[str]] = None,
names: Optional[Dict[str, str]] = None,
locales: Optional[Sequence[str]],
names: Optional[Dict[str, str]],
) -> None:
if locales is None:
locales = ["en"]
Expand Down Expand Up @@ -93,7 +93,8 @@ class City(PlaceRecord):

def __init__(
self,
locales: Optional[Sequence[str]] = None,
locales: Optional[Sequence[str]],
*,
confidence: Optional[int] = None,
geoname_id: Optional[int] = None,
names: Optional[Dict[str, str]] = None,
Expand Down Expand Up @@ -147,7 +148,8 @@ class Continent(PlaceRecord):

def __init__(
self,
locales: Optional[Sequence[str]] = None,
locales: Optional[Sequence[str]],
*,
code: Optional[str] = None,
geoname_id: Optional[int] = None,
names: Optional[Dict[str, str]] = None,
Expand Down Expand Up @@ -217,7 +219,8 @@ class Country(PlaceRecord):

def __init__(
self,
locales: Optional[Sequence[str]] = None,
locales: Optional[Sequence[str]],
*,
confidence: Optional[int] = None,
geoname_id: Optional[int] = None,
is_in_european_union: bool = False,
Expand Down Expand Up @@ -298,7 +301,8 @@ class RepresentedCountry(Country):

def __init__(
self,
locales: Optional[Sequence[str]] = None,
locales: Optional[Sequence[str]],
*,
confidence: Optional[int] = None,
geoname_id: Optional[int] = None,
is_in_european_union: bool = False,
Expand All @@ -310,7 +314,12 @@ def __init__(
) -> None:
self.type = type
super().__init__(
locales, confidence, geoname_id, is_in_european_union, iso_code, names
locales,
confidence=confidence,
geoname_id=geoname_id,
is_in_european_union=is_in_european_union,
iso_code=iso_code,
names=names,
)


Expand Down Expand Up @@ -391,6 +400,7 @@ class Location(Record):

def __init__(
self,
*,
average_income: Optional[int] = None,
accuracy_radius: Optional[int] = None,
latitude: Optional[float] = None,
Expand Down Expand Up @@ -425,7 +435,7 @@ class MaxMind(Record):

queries_remaining: Optional[int]

def __init__(self, queries_remaining: Optional[int] = None, **_) -> None:
def __init__(self, *, queries_remaining: Optional[int] = None, **_) -> None:
self.queries_remaining = queries_remaining


Expand Down Expand Up @@ -460,7 +470,7 @@ class Postal(Record):
confidence: Optional[int]

def __init__(
self, code: Optional[str] = None, confidence: Optional[int] = None, **_
self, *, code: Optional[str] = None, confidence: Optional[int] = None, **_
) -> None:
self.code = code
self.confidence = confidence
Expand Down Expand Up @@ -519,7 +529,8 @@ class Subdivision(PlaceRecord):

def __init__(
self,
locales: Optional[Sequence[str]] = None,
locales: Optional[Sequence[str]],
*,
confidence: Optional[int] = None,
geoname_id: Optional[int] = None,
iso_code: Optional[str] = None,
Expand Down Expand Up @@ -850,6 +861,7 @@ class Traits(Record):

def __init__(
self,
*,
autonomous_system_number: Optional[int] = None,
autonomous_system_organization: Optional[str] = None,
connection_type: Optional[str] = None,
Expand Down

0 comments on commit c84b047

Please sign in to comment.