Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade pylint black mypy voluptuous-stubs chardet==3.0.4 types-requests types-maxminddb
pip install --upgrade pylint black maxminddb mypy voluptuous-stubs chardet==3.0.4 types-requests

- name: Install
run: python setup.py install
Expand Down
12 changes: 12 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
History
-------

4.3.0
++++++++++++++++++

* Previously, the ``py.typed`` file was not being added to the source
distribution. It is now explicitly specified in the manifest.
* The type hints for the database file in the ``Reader`` constructor have
been expanded to match those specified by ``maxmindb.open_database``. In
particular, ``os.PathLike`` and ``IO`` have been added.
* Corrected the type hint for the ``metadata()`` method on ``Reader``. It
will return a ``maxminddb.extension.Metadata`` if the C extension is being
used.

4.2.0 (2021-05-12)
++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include HISTORY.rst README.rst LICENSE requirements.txt tests/*.py tests/data/test-data/*.mmdb
include HISTORY.rst README.rst LICENSE geoip2/py.typed requirements.txt tests/*.py tests/data/test-data/*.mmdb
graft docs/html
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,11 @@ Database Reader Exceptions
--------------------------

If the database file does not exist or is not readable, the constructor will
raise a ``FileNotFoundError``. If the IP address passed to a method is
invalid, a ``ValueError`` will be raised. If the file is invalid or there is a
bug in the reader, a ``maxminddb.InvalidDatabaseError`` will be raised with a
description of the problem. If an IP address is not in the database, a
``AddressNotFoundError`` will be raised.
raise a ``FileNotFoundError`` or a ``PermissionError``. If the IP address passed
to a method is invalid, a ``ValueError`` will be raised. If the file is invalid
or there is a bug in the reader, a ``maxminddb.InvalidDatabaseError`` will be
raised with a description of the problem. If an IP address is not in the
database, a ``AddressNotFoundError`` will be raised.

Values to use for Database or Dictionary Keys
---------------------------------------------
Expand Down
18 changes: 12 additions & 6 deletions geoip2/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

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

import maxminddb

Expand Down Expand Up @@ -59,13 +60,16 @@ class Reader:
"""

def __init__(
self, fileish: str, locales: Optional[List[str]] = None, mode: int = MODE_AUTO
self,
fileish: Union[AnyStr, int, os.PathLike, IO],
locales: Optional[List[str]] = None,
mode: int = MODE_AUTO,
) -> None:
"""Create GeoIP2 Reader.

:param fileish: The string path to the GeoIP2 database, or an existing
file descriptor pointing to the database. Note that this latter
usage is only valid when mode is MODE_FD.
:param fileish: A path to the GeoIP2 database or an existing file
descriptor pointing to the database. Note that a file descriptor
is only valid when mode is MODE_FD.
:param locales: This is list of locale codes. This argument will be
passed on to record classes to use when their name properties are
called. The default value is ['en'].
Expand Down Expand Up @@ -254,7 +258,9 @@ def _flat_model_for(
record["prefix_len"] = prefix_len
return model_class(record)

def metadata(self) -> maxminddb.reader.Metadata:
def metadata(
self,
) -> Union[maxminddb.reader.Metadata, "maxminddb.extension.Metadata"]:
"""The metadata for the open database.

:returns: :py:class:`maxminddb.reader.Metadata` object
Expand Down
2 changes: 1 addition & 1 deletion geoip2/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Record(SimpleEquality, metaclass=ABCMeta):
"""All records are subclasses of the abstract class ``Record``."""

def __repr__(self) -> str:
args = ", ".join("%s=%r" % x for x in self.__dict__.items())
args = ", ".join(f"{k}={v!r}" for k, v in self.__dict__.items())
return f"{self.__module__}.{self.__class__.__name__}({args})"


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
aiohttp>=3.6.2,<4.0.0
maxminddb>=2.0.0,<3.0.0
maxminddb>=2.1.0,<3.0.0
requests>=2.24.0,<3.0.0
urllib3>=1.25.2,<2.0.0