Skip to content

Commit b9b58d9

Browse files
authored
Update django.contrib.gis.geoip2 stubs (#2593)
From django/django@f5f55b4: - `django.contrib.gis.geoip2.GeoIP2.info` was removed. From django/django@60c7cb9: - `django.contrib.gis.geoip2.resources` was removed. From django/django@0ee2b8c: - `django.contrib.gis.geoip2.base` was removed. - `django.contrib.gis.geoip2` became a module instead of a package. From django/django@a93375e: - `django.contrib.gis.geoip2.GEOIP_SETTINGS` was removed. From django/django@cc56c22: - Support for querying using `IPv4Address` and `IPv6Address` was added. From django/django@f50184a: - `django.contrib.gis.geoip2.GeoIP2.city()` returns extra fields. - `django.contrib.gis.geoip2.GeoIP2.country()` returns extra fields. From django/django@3fad712: - `django.contrib.gis.geoip2.SUPPORTED_DATABASE_TYPES` was added. - `django.contrib.gis.geoip2.GeoIP2.is_city` was restored. - `django.contrib.gis.geoip2.GeoIP2.is_country` was restored.
1 parent 29e2ca8 commit b9b58d9

File tree

8 files changed

+77
-56
lines changed

8 files changed

+77
-56
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from collections.abc import Sequence
2+
from ipaddress import IPv4Address, IPv6Address
3+
from typing import Final, TypedDict
4+
5+
from _typeshed import StrPath
6+
from django.contrib.gis.geos import Point
7+
from django.utils.functional import cached_property
8+
from typing_extensions import Self, TypeAlias, deprecated
9+
10+
HAS_GEOIP2: bool
11+
SUPPORTED_DATABASE_TYPES: set[str]
12+
13+
_CoordType: TypeAlias = tuple[float, float] | tuple[None, None]
14+
_QueryType: TypeAlias = str | IPv4Address | IPv6Address
15+
16+
class _CityResponse(TypedDict):
17+
accuracy_radius: int | None
18+
city: str
19+
continent_code: str
20+
continent_name: str
21+
country_code: str
22+
country_name: str
23+
is_in_european_union: bool
24+
latitude: float
25+
longitude: float
26+
metro_code: int | None
27+
postal_code: str | None
28+
region_code: str | None
29+
region_name: str | None
30+
time_zone: str | None
31+
# Kept for backward compatibility.
32+
dma_code: int | None
33+
region: str | None
34+
35+
class _CountryResponse(TypedDict):
36+
continent_code: str
37+
continent_name: str
38+
country_code: str
39+
country_name: str
40+
is_in_european_union: bool
41+
42+
class GeoIP2Exception(Exception): ...
43+
44+
class GeoIP2:
45+
MODE_AUTO: Final = 0
46+
MODE_MMAP_EXT: Final = 1
47+
MODE_MMAP: Final = 2
48+
MODE_FILE: Final = 4
49+
MODE_MEMORY: Final = 8
50+
cache_options: Final[frozenset[int]]
51+
52+
def __init__(
53+
self,
54+
path: StrPath | None = None,
55+
cache: int = 0,
56+
country: str | None = None,
57+
city: str | None = None,
58+
) -> None: ...
59+
def __del__(self) -> None: ...
60+
@cached_property
61+
def is_city(self) -> bool: ...
62+
@cached_property
63+
def is_country(self) -> bool: ...
64+
def city(self, query: _QueryType) -> _CityResponse: ...
65+
def country_code(self, query: _QueryType) -> str: ...
66+
def country_name(self, query: _QueryType) -> str: ...
67+
def country(self, query: _QueryType) -> _CountryResponse: ...
68+
@deprecated("coords() is deprecated and will be removed in Django 6.0. Use lon_lat() instead.")
69+
def coords(self, query: _QueryType, ordering: Sequence[str] = ...) -> _CoordType: ...
70+
def lon_lat(self, query: _QueryType) -> _CoordType: ...
71+
def lat_lon(self, query: _QueryType) -> _CoordType: ...
72+
def geos(self, query: _QueryType) -> Point: ...
73+
@classmethod
74+
@deprecated("open() is deprecated and will be removed in Django 6.0. Use GeoIP2() instead.")
75+
def open(cls, full_path: StrPath | None, cache: int) -> Self: ...

django-stubs/contrib/gis/geoip2/__init__.pyi

Lines changed: 0 additions & 4 deletions
This file was deleted.

django-stubs/contrib/gis/geoip2/base.pyi

Lines changed: 0 additions & 41 deletions
This file was deleted.

django-stubs/contrib/gis/geoip2/resources.pyi

Lines changed: 0 additions & 4 deletions
This file was deleted.

scripts/stubtest/allowlist.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ django.contrib.gis.db.backends.base.operations.BaseSpatialOperations.select_exte
164164
django.contrib.gis.db.backends.mysql.features.DatabaseFeatures.django_test_skips
165165
django.contrib.gis.db.backends.mysql.features.DatabaseFeatures.supports_geometry_field_unique_index
166166
django.contrib.gis.db.backends.mysql.operations.MySQLOperations.collect
167-
django.contrib.gis.geoip2.GeoIP2.is_country
168-
django.contrib.gis.geoip2.GeoIP2.is_city
169167
django.contrib.gis.db.backends.mysql.operations.MySQLOperations.from_text
170168
django.contrib.gis.db.backends.mysql.operations.MySQLOperations.gis_operators
171169
django.contrib.gis.db.backends.mysql.operations.MySQLOperations.mariadb
@@ -206,6 +204,8 @@ django.contrib.gis.gdal.GDALRaster.driver
206204
django.contrib.gis.gdal.GDALRaster.is_vsi_based
207205
django.contrib.gis.gdal.raster.source.GDALRaster.driver
208206
django.contrib.gis.gdal.raster.source.GDALRaster.is_vsi_based
207+
django.contrib.gis.geoip2.GeoIP2.is_city
208+
django.contrib.gis.geoip2.GeoIP2.is_country
209209
django.contrib.postgres.expressions.ArraySubquery.output_field
210210
django.contrib.postgres.indexes.PostgresIndex.max_name_length
211211
django.contrib.sessions.backends.db.SessionStore.model

scripts/stubtest/allowlist_todo.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ django.contrib.gis.gdal.raster.const.VSI_FILESYSTEM_PREFIX
401401
django.contrib.gis.gdal.raster.const.VSI_MEM_FILESYSTEM_BASE_PATH
402402
django.contrib.gis.gdal.srs.SpatialReference.pretty_wkt
403403
django.contrib.gis.gdal.srs.SpatialReference.xml
404-
django.contrib.gis.geoip2.base
405404
django.contrib.gis.geos.Point.tuple
406405
django.contrib.gis.geos.geometry.GEOSGeometryBase.geojson
407406
django.contrib.gis.geos.geometry.GEOSGeometryBase.make_valid

scripts/stubtest/allowlist_todo_django51.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ django.contrib.gis.gdal.prototypes.raster.get_driver_by_name
3030
django.contrib.gis.gdal.prototypes.raster.get_driver_count
3131
django.contrib.gis.gdal.prototypes.raster.get_driver_description
3232
django.contrib.gis.gdal.prototypes.raster.register_all
33-
django.contrib.gis.geoip2.GeoIP2.info
34-
django.contrib.gis.geoip2.resources
3533
django.contrib.postgres.indexes.BTreeIndex.__init__
3634
django.db.backends.oracle.features.DatabaseFeatures.bare_select_suffix
3735
django.db.backends.oracle.features.DatabaseFeatures.supports_aggregation_over_interval_types

tests/typecheck/test_import_all.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@
177177
import django.contrib.gis.gdal.raster.source
178178
import django.contrib.gis.gdal.srs
179179
import django.contrib.gis.geoip2
180-
import django.contrib.gis.geoip2.base
181-
import django.contrib.gis.geoip2.resources
182180
import django.contrib.gis.geometry
183181
import django.contrib.gis.geos
184182
import django.contrib.gis.geos.base

0 commit comments

Comments
 (0)