11from collections .abc import Iterable
2- from typing import Any , NamedTuple , TypeVar
2+ from typing import Any , Generic , NamedTuple , TypeVar , type_check_only
33
44from django .contrib .gis import forms
55from django .contrib .gis .geos import (
@@ -23,18 +23,66 @@ _ST = TypeVar("_ST")
2323# __get__ return type
2424_GT = TypeVar ("_GT" )
2525
26+ _ST_PointField = TypeVar ("_ST_PointField" , default = Point | Combinable )
27+ _GT_PointField = TypeVar ("_GT_PointField" , default = Point )
28+ _Form_PointField = TypeVar ("_Form_PointField" , bound = forms .PointField , default = forms .PointField )
29+ _Geom_PointField = TypeVar ("_Geom_PointField" , bound = Point , default = Point )
30+
31+ _ST_LineStringField = TypeVar ("_ST_LineStringField" , default = LineString | Combinable )
32+ _GT_LineStringField = TypeVar ("_GT_LineStringField" , default = LineString )
33+ _Form_LineStringField = TypeVar ("_Form_LineStringField" , bound = forms .LineStringField , default = forms .LineStringField )
34+ _Geom_LineStringField = TypeVar ("_Geom_LineStringField" , bound = LineString , default = LineString )
35+
36+ _ST_PolygonField = TypeVar ("_ST_PolygonField" , default = Polygon | Combinable )
37+ _GT_PolygonField = TypeVar ("_GT_PolygonField" , default = Polygon )
38+ _Form_PolygonField = TypeVar ("_Form_PolygonField" , bound = forms .PolygonField , default = forms .PolygonField )
39+ _Geom_PolygonField = TypeVar ("_Geom_PolygonField" , bound = Polygon , default = Polygon )
40+
41+ _ST_MultiPointField = TypeVar ("_ST_MultiPointField" , default = MultiPoint | Combinable )
42+ _GT_MultiPointField = TypeVar ("_GT_MultiPointField" , default = MultiPoint )
43+ _Form_MultiPointField = TypeVar ("_Form_MultiPointField" , bound = forms .MultiPointField , default = forms .MultiPointField )
44+ _Geom_MultiPointField = TypeVar ("_Geom_MultiPointField" , bound = MultiPoint , default = MultiPoint )
45+
46+ _ST_MultiLineStringField = TypeVar ("_ST_MultiLineStringField" , default = MultiLineString | Combinable )
47+ _GT_MultiLineStringField = TypeVar ("_GT_MultiLineStringField" , default = MultiLineString )
48+ _Form_MultiLineStringField = TypeVar (
49+ "_Form_MultiLineStringField" , bound = forms .MultiLineStringField , default = forms .MultiLineStringField
50+ )
51+ _Geom_MultiLineStringField = TypeVar ("_Geom_MultiLineStringField" , bound = MultiLineString , default = MultiLineString )
52+
53+ _ST_MultiPolygonField = TypeVar ("_ST_MultiPolygonField" , default = MultiPolygon | Combinable )
54+ _GT_MultiPolygonField = TypeVar ("_GT_MultiPolygonField" , default = MultiPolygon )
55+ _Form_MultiPolygonField = TypeVar (
56+ "_Form_MultiPolygonField" , bound = forms .MultiPolygonField , default = forms .MultiPolygonField
57+ )
58+ _Geom_MultiPolygonField = TypeVar ("_Geom_MultiPolygonField" , bound = MultiPolygon , default = MultiPolygon )
59+
60+ _ST_GeometryCollectionField = TypeVar ("_ST_GeometryCollectionField" , default = GeometryCollection | Combinable )
61+ _GT_GeometryCollectionField = TypeVar ("_GT_GeometryCollectionField" , default = GeometryCollection )
62+ _Form_GeometryCollectionField = TypeVar (
63+ "_Form_GeometryCollectionField" , bound = forms .GeometryCollectionField , default = forms .GeometryCollectionField
64+ )
65+ _Geom_GeometryCollectionField = TypeVar (
66+ "_Geom_GeometryCollectionField" , bound = GeometryCollection , default = GeometryCollection
67+ )
68+
69+ _Form_ClassT = TypeVar ("_Form_ClassT" , bound = forms .GeometryField )
70+ _GEOM_ClassT = TypeVar ("_GEOM_ClassT" , bound = GEOSGeometry )
71+
2672class SRIDCacheEntry (NamedTuple ):
2773 units : Any
2874 units_name : str
2975 spheroid : str
3076 geodetic : bool
3177
3278def get_srid_info (srid : int , connection : Any ) -> SRIDCacheEntry : ...
79+ @type_check_only
80+ class SpatialClassField (Generic [_Form_ClassT , _GEOM_ClassT ]):
81+ form_class : type [_Form_ClassT ]
82+ geom_class : type [_GEOM_ClassT ] | None
3383
34- class BaseSpatialField (Field [_ST , _GT ]):
35- form_class : type [forms .GeometryField ]
84+ class BaseSpatialField (Field [_ST , _GT ], SpatialClassField [_Form_ClassT , _GEOM_ClassT ]):
3685 geom_type : str
37- geom_class : type [GEOSGeometry ] | None
3886 geography : bool
3987 spatial_index : bool
4088 srid : int
@@ -52,7 +100,7 @@ class BaseSpatialField(Field[_ST, _GT]):
52100 null : bool = ...,
53101 db_index : bool = ...,
54102 default : Any = ...,
55- db_default : type [NOT_PROVIDED ] | Expression | _ST = ...,
103+ db_default : type [NOT_PROVIDED ] | Expression | _ST = ..., # pyright: ignore[reportInvalidTypeVarUse]
56104 editable : bool = ...,
57105 auto_created : bool = ...,
58106 serialize : bool = ...,
@@ -78,7 +126,7 @@ class BaseSpatialField(Field[_ST, _GT]):
78126 def get_raster_prep_value (self , value : Any , is_candidate : Any ) -> Any : ...
79127 def get_prep_value (self , value : Any ) -> Any : ...
80128
81- class GeometryField (BaseSpatialField [_ST , _GT ]):
129+ class GeometryField (BaseSpatialField [_ST , _GT , _Form_ClassT , _GEOM_ClassT ]):
82130 dim : int
83131 def __init__ (
84132 self ,
@@ -98,7 +146,7 @@ class GeometryField(BaseSpatialField[_ST, _GT]):
98146 null : bool = ...,
99147 db_index : bool = ...,
100148 default : Any = ...,
101- db_default : type [NOT_PROVIDED ] | Expression | _ST = ...,
149+ db_default : type [NOT_PROVIDED ] | Expression | _ST = ..., # pyright: ignore[reportInvalidTypeVarUse]
102150 editable : bool = ...,
103151 auto_created : bool = ...,
104152 serialize : bool = ...,
@@ -122,62 +170,58 @@ class GeometryField(BaseSpatialField[_ST, _GT]):
122170 ** kwargs : Any ,
123171 ) -> forms .GeometryField : ...
124172
125- class PointField (GeometryField [_ST , _GT ]):
173+ class PointField (GeometryField [_ST_PointField , _GT_PointField , _Form_PointField , _Geom_PointField ]):
126174 _pyi_private_set_type : Point | Combinable
127175 _pyi_private_get_type : Point
128176 _pyi_lookup_exact_type : Point
129177
130- geom_class : type [Point ]
131- form_class : type [forms .PointField ]
132-
133- class LineStringField (GeometryField [_ST , _GT ]):
178+ class LineStringField (
179+ GeometryField [_ST_LineStringField , _GT_LineStringField , _Form_LineStringField , _Geom_LineStringField ]
180+ ):
134181 _pyi_private_set_type : LineString | Combinable
135182 _pyi_private_get_type : LineString
136183 _pyi_lookup_exact_type : LineString
137184
138- geom_class : type [LineString ]
139- form_class : type [forms .LineStringField ]
140-
141- class PolygonField (GeometryField [_ST , _GT ]):
185+ class PolygonField (GeometryField [_ST_PolygonField , _GT_PolygonField , _Form_PolygonField , _Geom_PolygonField ]):
142186 _pyi_private_set_type : Polygon | Combinable
143187 _pyi_private_get_type : Polygon
144188 _pyi_lookup_exact_type : Polygon
145189
146- geom_class : type [Polygon ]
147- form_class : type [forms .PolygonField ]
148-
149- class MultiPointField (GeometryField [_ST , _GT ]):
190+ class MultiPointField (
191+ GeometryField [_ST_MultiPointField , _GT_MultiPointField , _Form_MultiPointField , _Geom_MultiPointField ]
192+ ):
150193 _pyi_private_set_type : MultiPoint | Combinable
151194 _pyi_private_get_type : MultiPoint
152195 _pyi_lookup_exact_type : MultiPoint
153196
154- geom_class : type [MultiPoint ]
155- form_class : type [forms .MultiPointField ]
156-
157- class MultiLineStringField (GeometryField [_ST , _GT ]):
197+ class MultiLineStringField (
198+ GeometryField [
199+ _ST_MultiLineStringField , _GT_MultiLineStringField , _Form_MultiLineStringField , _Geom_MultiLineStringField
200+ ]
201+ ):
158202 _pyi_private_set_type : MultiLineString | Combinable
159203 _pyi_private_get_type : MultiLineString
160204 _pyi_lookup_exact_type : MultiLineString
161205
162- geom_class : type [MultiLineString ]
163- form_class : type [forms .MultiLineStringField ]
164-
165- class MultiPolygonField (GeometryField [_ST , _GT ]):
206+ class MultiPolygonField (
207+ GeometryField [_ST_MultiPolygonField , _GT_MultiPolygonField , _Form_MultiPolygonField , _Geom_MultiPolygonField ]
208+ ):
166209 _pyi_private_set_type : MultiPolygon | Combinable
167210 _pyi_private_get_type : MultiPolygon
168211 _pyi_lookup_exact_type : MultiPolygon
169212
170- geom_class : type [MultiPolygon ]
171- form_class : type [forms .MultiPolygonField ]
172-
173- class GeometryCollectionField (GeometryField [_ST , _GT ]):
213+ class GeometryCollectionField (
214+ GeometryField [
215+ _ST_GeometryCollectionField ,
216+ _GT_GeometryCollectionField ,
217+ _Form_GeometryCollectionField ,
218+ _Geom_GeometryCollectionField ,
219+ ]
220+ ):
174221 _pyi_private_set_type : GeometryCollection | Combinable
175222 _pyi_private_get_type : GeometryCollection
176223 _pyi_lookup_exact_type : GeometryCollection
177224
178- geom_class : type [GeometryCollection ]
179- form_class : type [forms .GeometryCollectionField ]
180-
181225class ExtentField (Field ):
182226 def get_internal_type (self ) -> Any : ...
183227
0 commit comments