Skip to content

Switch to ruff #204

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

Merged
merged 17 commits into from
May 23, 2025
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
51 changes: 45 additions & 6 deletions maxminddb/extension.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""C extension database reader and related classes."""

from ipaddress import IPv4Address, IPv6Address
from os import PathLike
from typing import IO, Any, AnyStr
Expand All @@ -7,24 +9,60 @@ from typing_extensions import Self
from maxminddb.types import Record

class Reader:
"""A C extension implementation of a reader for the MaxMind DB format.

IP addresses can be looked up using the ``get`` method.
"""

closed: bool = ...

def __init__(
self,
database: AnyStr | int | PathLike | IO,
mode: int = ...,
) -> None: ...
def close(self) -> None: ...
def get(self, ip_address: str | IPv6Address | IPv4Address) -> Record | None: ...
) -> None:
"""Reader for the MaxMind DB file format.

Arguments:
database: A path to a valid MaxMind DB file such as a GeoIP2 database
file, or a file descriptor in the case of MODE_FD.
mode: mode to open the database with. The only supported modes are
MODE_AUTO and MODE_MMAP_EXT.

"""

def close(self) -> None:
"""Close the MaxMind DB file and returns the resources to the system."""

def get(self, ip_address: str | IPv6Address | IPv4Address) -> Record | None:
"""Return the record for the ip_address in the MaxMind DB.

Arguments:
ip_address: an IP address in the standard string notation

"""

def get_with_prefix_len(
self,
ip_address: str | IPv6Address | IPv4Address,
) -> tuple[Record | None, int]: ...
def metadata(self) -> Metadata: ...
) -> tuple[Record | None, int]:
"""Return a tuple with the record and the associated prefix length.

Arguments:
ip_address: an IP address in the standard string notation

"""

def metadata(self) -> Metadata:
"""Return the metadata associated with the MaxMind DB file."""

def __enter__(self) -> Self: ...
def __exit__(self, *args) -> None: ... # noqa: ANN002

# pylint: disable=too-few-public-methods
Copy link
Contributor

Choose a reason for hiding this comment

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

Would we want to delete this pylint comment?

class Metadata:
"""Metadata for the MaxMind DB reader."""

binary_format_major_version: int
"""
The major version number of the binary format used when creating the
Expand Down Expand Up @@ -74,4 +112,5 @@ class Metadata:
The bit size of a record in the search tree.
"""

def __init__(self, **kwargs: Any) -> None: ... # noqa: ANN401
def __init__(self, **kwargs: Any) -> None: # noqa: ANN401
"""Create new Metadata object. kwargs are key/value pairs from spec."""
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ ignore = [

[tool.ruff.lint.per-file-ignores]
"docs/*" = ["ALL"]
"maxminddb/extension.pyi" = [
# This is a stub for extension and having the docs here is useful.
"PYI021",
]
"setup.py" = ["ALL"]
"tests/*" = ["ANN201", "D"]

Expand Down
Loading