diff --git a/django-stubs/contrib/gis/db/models/functions.pyi b/django-stubs/contrib/gis/db/models/functions.pyi index bee8e4076..ff12bea3c 100644 --- a/django-stubs/contrib/gis/db/models/functions.pyi +++ b/django-stubs/contrib/gis/db/models/functions.pyi @@ -20,13 +20,21 @@ class GeoFuncMixin: def name(self) -> str: ... @cached_property def geo_field(self) -> Any: ... + def as_sql( + self, + compiler: SQLCompiler, + connection: BaseDatabaseWrapper, + function: str | None = None, + **extra_context: Any, + ) -> _AsSqlType: ... def resolve_expression( self, *args: Any, **kwargs: Any, ) -> Any: ... -class GeoFunc(GeoFuncMixin, Func): ... +class GeoFunc(GeoFuncMixin, Func): # type: ignore[misc] + ... class GeomOutputGeoFunc(GeoFunc): @cached_property @@ -46,6 +54,10 @@ class Area(OracleToleranceMixin, GeoFunc): @override def output_field(self) -> AreaField: ... @override + def as_sql( # type: ignore[override] + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any + ) -> _AsSqlType: ... + @override def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... class Azimuth(GeoFunc): @@ -82,19 +94,19 @@ class AsWKT(GeoFunc): output_field: ClassVar[TextField] arity: int -class BoundingCircle(OracleToleranceMixin, GeomOutputGeoFunc): +class BoundingCircle(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] def __init__(self, expression: Any, num_seg: int = 48, **extra: Any) -> None: ... @override def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... -class Centroid(OracleToleranceMixin, GeomOutputGeoFunc): +class Centroid(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] arity: int class ClosestPoint(GeomOutputGeoFunc): arity: int geom_param_pos: tuple[int, int] -class Difference(OracleToleranceMixin, GeomOutputGeoFunc): +class Difference(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] arity: int geom_param_pos: Any @@ -103,7 +115,7 @@ class DistanceResultMixin: def output_field(self) -> DistanceField: ... def source_is_geography(self) -> Any: ... -class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc): +class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc): # type: ignore[misc] geom_param_pos: Any spheroid: Any def __init__(self, expr1: Any, expr2: Any, spheroid: Any | None = None, **extra: Any) -> None: ... @@ -138,20 +150,20 @@ class GeometryDistance(GeoFunc): arg_joiner: str geom_param_pos: Any -class Intersection(OracleToleranceMixin, GeomOutputGeoFunc): +class Intersection(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] arity: int geom_param_pos: Any -class GeometryType(GeoFuncMixin, StandardTransform): +class GeometryType(GeoFuncMixin, StandardTransform): # type: ignore[misc] lookup_name: str output_field: ClassVar[CharField] def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... -class IsEmpty(GeoFuncMixin, StandardTransform): +class IsEmpty(GeoFuncMixin, StandardTransform): # type: ignore[misc] lookup_name: str output_field: ClassVar[BooleanField] -class IsValid(OracleToleranceMixin, GeoFuncMixin, StandardTransform): +class IsValid(OracleToleranceMixin, GeoFuncMixin, StandardTransform): # type: ignore[misc] lookup_name: str output_field: ClassVar[BooleanField] @override @@ -160,6 +172,10 @@ class IsValid(OracleToleranceMixin, GeoFuncMixin, StandardTransform): class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc): spheroid: Any def __init__(self, expr1: Any, spheroid: bool = True, **extra: Any) -> None: ... + @override + def as_sql( # type: ignore[override] + self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any + ) -> _AsSqlType: ... def as_postgresql( self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any ) -> _AsSqlType: ... @@ -185,7 +201,7 @@ class NumPoints(GeoFunc): output_field: ClassVar[IntegerField] arity: int -class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc): +class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc): # type: ignore[misc] arity: int def as_postgresql( self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any @@ -193,7 +209,7 @@ class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc): @override def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... -class PointOnSurface(OracleToleranceMixin, GeomOutputGeoFunc): +class PointOnSurface(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] arity: int class Reverse(GeoFunc): @@ -202,13 +218,13 @@ class Reverse(GeoFunc): class Rotate(GeomOutputGeoFunc): def __init__(self, expression: Any, angle: Any, origin: Any | None = None, **extra: Any) -> None: ... -class Scale(SQLiteDecimalToFloatMixin, GeomOutputGeoFunc): +class Scale(SQLiteDecimalToFloatMixin, GeomOutputGeoFunc): # type: ignore[misc] def __init__(self, expression: Any, x: Any, y: Any, z: float = 0.0, **extra: Any) -> None: ... -class SnapToGrid(SQLiteDecimalToFloatMixin, GeomOutputGeoFunc): +class SnapToGrid(SQLiteDecimalToFloatMixin, GeomOutputGeoFunc): # type: ignore[misc] def __init__(self, expression: Any, *args: Any, **extra: Any) -> None: ... -class SymDifference(OracleToleranceMixin, GeomOutputGeoFunc): +class SymDifference(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] arity: int geom_param_pos: Any @@ -219,6 +235,6 @@ class Translate(Scale): @override def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ... -class Union(OracleToleranceMixin, GeomOutputGeoFunc): +class Union(OracleToleranceMixin, GeomOutputGeoFunc): # type: ignore[misc] arity: int geom_param_pos: Any diff --git a/django-stubs/contrib/gis/db/models/lookups.pyi b/django-stubs/contrib/gis/db/models/lookups.pyi index 202559447..9c7b4a901 100644 --- a/django-stubs/contrib/gis/db/models/lookups.pyi +++ b/django-stubs/contrib/gis/db/models/lookups.pyi @@ -1,9 +1,13 @@ from typing import Any +from django.db.backends.base.base import BaseDatabaseWrapper from django.db.models import Lookup, Transform +from django.db.models.sql.compiler import SQLCompiler, _AsSqlType from typing_extensions import override -class RasterBandTransform(Transform): ... +class RasterBandTransform(Transform): + @override + def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override] class GISLookup(Lookup): sql_template: Any diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index ac5d27a21..3cb02bee7 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -79,10 +79,6 @@ django.contrib.gis.admin.site django.contrib.gis.db.backends.spatialite.base.DatabaseWrapper.ops django.contrib.gis.db.models.CharField.description django.contrib.gis.db.models.Field.description -django.contrib.gis.db.models.functions.Area.as_sql -django.contrib.gis.db.models.functions.GeoFuncMixin.as_sql -django.contrib.gis.db.models.functions.Length.as_sql -django.contrib.gis.db.models.lookups.RasterBandTransform.as_sql django.contrib.gis.forms.inlineformset_factory django.contrib.gis.forms.modelformset_factory django.contrib.redirects.models.Redirect.id