Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow locales to be a sequence #188

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ History

* ``metro_code`` on ``geoip2.record.Location`` has been deprecated. The
code values are no longer being maintained.
* The type hinting for the optional `locales` keyword argument now allows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be two `s?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! We need an reStructuredText linter as I am always trying to write Markdown.

any sequence of strings rather than only list of strings.

4.8.1 (2024-11-18)
++++++++++++++++++
Expand Down
4 changes: 2 additions & 2 deletions geoip2/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import inspect
import os
from typing import Any, AnyStr, cast, IO, List, Optional, Type, Union
from typing import Any, AnyStr, cast, IO, Optional, Sequence, Type, Union

import maxminddb

Expand Down Expand Up @@ -72,7 +72,7 @@ class Reader:
def __init__(
self,
fileish: Union[AnyStr, int, os.PathLike, IO],
locales: Optional[List[str]] = None,
locales: Optional[Sequence[str]] = None,
mode: int = MODE_AUTO,
) -> None:
"""Create GeoIP2 Reader.
Expand Down
6 changes: 3 additions & 3 deletions geoip2/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# pylint: disable=too-many-instance-attributes,too-few-public-methods
import ipaddress
from abc import ABCMeta
from typing import Any, cast, Dict, List, Optional, Union
from typing import Any, cast, Dict, Optional, Sequence, Union

import geoip2.records
from geoip2.mixins import SimpleEquality
Expand Down Expand Up @@ -76,7 +76,7 @@ class Country(SimpleEquality):
traits: geoip2.records.Traits

def __init__(
self, raw_response: Dict[str, Any], locales: Optional[List[str]] = None
self, raw_response: Dict[str, Any], locales: Optional[Sequence[str]] = None
) -> None:
if locales is None:
locales = ["en"]
Expand Down Expand Up @@ -182,7 +182,7 @@ class City(Country):
subdivisions: geoip2.records.Subdivisions

def __init__(
self, raw_response: Dict[str, Any], locales: Optional[List[str]] = None
self, raw_response: Dict[str, Any], locales: Optional[Sequence[str]] = None
) -> None:
super().__init__(raw_response, locales)
self.city = geoip2.records.City(locales, **raw_response.get("city", {}))
Expand Down
20 changes: 10 additions & 10 deletions geoip2/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# pylint:disable=R0903
from abc import ABCMeta
from typing import Dict, List, Optional, Type, Union
from typing import Dict, Optional, Type, Sequence, Union

from geoip2.mixins import SimpleEquality

Expand All @@ -28,11 +28,11 @@ class PlaceRecord(Record, metaclass=ABCMeta):
"""All records with :py:attr:`names` subclass :py:class:`PlaceRecord`."""

names: Dict[str, str]
_locales: List[str]
_locales: Sequence[str]

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

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

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

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

def __init__(
self,
locales: Optional[List[str]] = None,
locales: Optional[Sequence[str]] = None,
confidence: Optional[int] = None,
geoname_id: Optional[int] = None,
is_in_european_union: bool = False,
Expand Down Expand Up @@ -519,7 +519,7 @@ class Subdivision(PlaceRecord):

def __init__(
self,
locales: Optional[List[str]] = None,
locales: Optional[Sequence[str]] = None,
confidence: Optional[int] = None,
geoname_id: Optional[int] = None,
iso_code: Optional[str] = None,
Expand All @@ -545,14 +545,14 @@ class Subdivisions(tuple):
"""

def __new__(
cls: Type["Subdivisions"], locales: Optional[List[str]], *subdivisions
cls: Type["Subdivisions"], locales: Optional[Sequence[str]], *subdivisions
) -> "Subdivisions":
subobjs = tuple(Subdivision(locales, **x) for x in subdivisions)
obj = super().__new__(cls, subobjs) # type: ignore
return obj

def __init__(
self, locales: Optional[List[str]], *subdivisions # pylint:disable=W0613
self, locales: Optional[Sequence[str]], *subdivisions # pylint:disable=W0613
) -> None:
self._locales = locales
super().__init__()
Expand Down
10 changes: 5 additions & 5 deletions geoip2/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import ipaddress
import json
from typing import Any, Dict, cast, List, Optional, Type, Union
from typing import Any, Dict, cast, Optional, Sequence, Type, Union

import aiohttp
import aiohttp.http
Expand Down Expand Up @@ -61,15 +61,15 @@ class BaseClient: # pylint: disable=missing-class-docstring, too-few-public-met
_account_id: str
_host: str
_license_key: str
_locales: List[str]
_locales: Sequence[str]
_timeout: float

def __init__(
self,
account_id: int,
license_key: str,
host: str,
locales: Optional[List[str]],
locales: Optional[Sequence[str]],
timeout: float,
) -> None:
"""Construct a Client."""
Expand Down Expand Up @@ -265,7 +265,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-positional-argument
account_id: int,
license_key: str,
host: str = "geoip.maxmind.com",
locales: Optional[List[str]] = None,
locales: Optional[Sequence[str]] = None,
timeout: float = 60,
proxy: Optional[str] = None,
) -> None:
Expand Down Expand Up @@ -428,7 +428,7 @@ def __init__( # pylint: disable=too-many-arguments,too-many-positional-argument
account_id: int,
license_key: str,
host: str = "geoip.maxmind.com",
locales: Optional[List[str]] = None,
locales: Optional[Sequence[str]] = None,
timeout: float = 60,
proxy: Optional[str] = None,
) -> None:
Expand Down
Loading