Skip to content
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

Update Expression classes output_field to @cached_property or ClassVar and improve type #1769

Merged
Merged
6 changes: 4 additions & 2 deletions django-stubs/contrib/gis/db/backends/postgis/operations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ from typing import Any, Literal

from django.contrib.gis.db.backends.base.operations import BaseSpatialOperations
from django.contrib.gis.db.backends.utils import SpatialOperator
from django.contrib.gis.db.models.fields import GeometryField
from django.db.backends.postgresql.operations import DatabaseOperations
from django.db.models import Func
from django.utils.functional import cached_property

BILATERAL: Literal["bilateral"]

Expand All @@ -16,8 +18,8 @@ class PostGISOperator(SpatialOperator):
class ST_Polygon(Func):
function: str
def __init__(self, expr: Any) -> None: ...
@property
def output_field(self) -> Any: ...
@cached_property
def output_field(self) -> GeometryField: ...

class PostGISOperations(BaseSpatialOperations, DatabaseOperations):
name: str
Expand Down
53 changes: 28 additions & 25 deletions django-stubs/contrib/gis/db/models/functions.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import Any
from typing import Any, ClassVar

from django.contrib.gis.db.models.fields import GeometryField
from django.contrib.gis.db.models.sql.conversion import AreaField, DistanceField
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Func
from django.db.models import BinaryField, BooleanField, FloatField, Func, IntegerField, TextField
from django.db.models import Transform as StandardTransform
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from django.utils.functional import cached_property

NUMERIC_TYPES: Any

Expand All @@ -15,8 +18,8 @@ class GeoFuncMixin:
class GeoFunc(GeoFuncMixin, Func): ...

class GeomOutputGeoFunc(GeoFunc):
@property
def output_field(self) -> Any: ...
@cached_property
def output_field(self) -> GeometryField: ...

class SQLiteDecimalToFloatMixin:
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...
Expand All @@ -27,42 +30,42 @@ class OracleToleranceMixin:

class Area(OracleToleranceMixin, GeoFunc):
arity: int
@property
def output_field(self) -> Any: ...
@cached_property
def output_field(self) -> AreaField: ...
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class Azimuth(GeoFunc):
output_field: Any
output_field: ClassVar[FloatField]
arity: int
geom_param_pos: Any

class AsGeoJSON(GeoFunc):
output_field: Any
output_field: ClassVar[TextField]
def __init__(
self, expression: Any, bbox: bool = ..., crs: bool = ..., precision: int = ..., **extra: Any
) -> None: ...
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class AsGML(GeoFunc):
geom_param_pos: Any
output_field: Any
output_field: ClassVar[TextField]
def __init__(self, expression: Any, version: int = ..., precision: int = ..., **extra: Any) -> None: ...
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class AsKML(GeoFunc):
output_field: Any
output_field: ClassVar[TextField]
def __init__(self, expression: Any, precision: int = ..., **extra: Any) -> None: ...

class AsSVG(GeoFunc):
output_field: Any
output_field: ClassVar[TextField]
def __init__(self, expression: Any, relative: bool = ..., precision: int = ..., **extra: Any) -> None: ...

class AsWKB(GeoFunc):
output_field: Any
output_field: ClassVar[BinaryField]
arity: int

class AsWKT(GeoFunc):
output_field: Any
output_field: ClassVar[TextField]
arity: int

class BoundingCircle(OracleToleranceMixin, GeomOutputGeoFunc):
Expand All @@ -77,8 +80,8 @@ class Difference(OracleToleranceMixin, GeomOutputGeoFunc):
geom_param_pos: Any

class DistanceResultMixin:
@property
def output_field(self) -> Any: ...
@cached_property
def output_field(self) -> DistanceField: ...
def source_is_geography(self) -> Any: ...

class Distance(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
Expand All @@ -97,20 +100,20 @@ class ForcePolygonCW(GeomOutputGeoFunc):
arity: int

class FromWKB(GeoFunc):
output_field: Any
output_field: ClassVar[GeometryField]
arity: int

class FromWKT(GeoFunc):
output_field: Any
output_field: ClassVar[GeometryField]
arity: int

class GeoHash(GeoFunc):
output_field: Any
output_field: ClassVar[TextField]
def __init__(self, expression: Any, precision: Any | None = ..., **extra: Any) -> None: ...
def as_mysql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class GeometryDistance(GeoFunc):
output_field: Any
output_field: ClassVar[FloatField]
arity: int
function: str
arg_joiner: str
Expand All @@ -122,11 +125,11 @@ class Intersection(OracleToleranceMixin, GeomOutputGeoFunc):

class IsEmpty(GeoFuncMixin, StandardTransform):
lookup_name: str
output_field: Any
output_field: ClassVar[BooleanField]

class IsValid(OracleToleranceMixin, GeoFuncMixin, StandardTransform):
lookup_name: str
output_field: Any
output_field: ClassVar[BooleanField]
def as_oracle(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
Expand All @@ -138,22 +141,22 @@ class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
def as_sqlite(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper, **extra_context: Any) -> _AsSqlType: ...

class LineLocatePoint(GeoFunc):
output_field: Any
output_field: ClassVar[FloatField]
arity: int
geom_param_pos: Any

class MakeValid(GeomOutputGeoFunc): ...

class MemSize(GeoFunc):
output_field: Any
output_field: ClassVar[IntegerField]
arity: int

class NumGeometries(GeoFunc):
output_field: Any
output_field: ClassVar[IntegerField]
arity: int

class NumPoints(GeoFunc):
output_field: Any
output_field: ClassVar[IntegerField]
arity: int

class Perimeter(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
Expand Down
26 changes: 20 additions & 6 deletions django-stubs/contrib/postgres/aggregates/general.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
from django.db.models.aggregates import Aggregate
from typing import ClassVar

from django.contrib.postgres.fields import ArrayField
from django.db.models import Aggregate, BooleanField, JSONField, TextField

from .mixins import OrderableAggMixin

class ArrayAgg(OrderableAggMixin, Aggregate): ...
class ArrayAgg(OrderableAggMixin, Aggregate):
@property
def output_field(self) -> ArrayField: ...

class BitAnd(Aggregate): ...
class BitOr(Aggregate): ...
class BoolAnd(Aggregate): ...
class BoolOr(Aggregate): ...
class JSONBAgg(OrderableAggMixin, Aggregate): ...
class StringAgg(OrderableAggMixin, Aggregate): ...

class BoolAnd(Aggregate):
output_field: ClassVar[BooleanField]

class BoolOr(Aggregate):
output_field: ClassVar[BooleanField]

class JSONBAgg(OrderableAggMixin, Aggregate):
output_field: ClassVar[JSONField]

class StringAgg(OrderableAggMixin, Aggregate):
output_field: ClassVar[TextField]
13 changes: 10 additions & 3 deletions django-stubs/contrib/postgres/aggregates/statistics.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from django.db.models.aggregates import Aggregate
from typing import ClassVar

from django.db.models import Aggregate, FloatField, IntegerField

class StatAggregate(Aggregate):
output_field: ClassVar[FloatField]

class StatAggregate(Aggregate): ...
class Corr(StatAggregate): ...
class CovarPop(StatAggregate): ...
class RegrAvgX(StatAggregate): ...
class RegrAvgY(StatAggregate): ...
class RegrCount(StatAggregate): ...

class RegrCount(StatAggregate):
output_field: ClassVar[IntegerField] # type: ignore[assignment]

class RegrIntercept(StatAggregate): ...
class RegrR2(StatAggregate): ...
class RegrSlope(StatAggregate): ...
Expand Down
14 changes: 10 additions & 4 deletions django-stubs/contrib/postgres/fields/hstore.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
from typing import Any
from typing import Any, ClassVar

from django.db.models import Field, Transform
from django.contrib.postgres.fields.array import ArrayField
from django.db.models import Field, TextField, Transform
from django.db.models.fields.mixins import CheckFieldDefaultMixin

class HStoreField(CheckFieldDefaultMixin, Field):
def get_transform(self, name: str) -> Any: ...

class KeyTransform(Transform):
output_field: ClassVar[TextField]

def __init__(self, key_name: str, *args: Any, **kwargs: Any) -> None: ...

class KeyTransformFactory:
def __init__(self, key_name: str) -> None: ...
def __call__(self, *args: Any, **kwargs: Any) -> KeyTransform: ...

class KeysTransform(Transform): ...
class ValuesTransform(Transform): ...
class KeysTransform(Transform):
output_field: ClassVar[ArrayField]

class ValuesTransform(Transform):
output_field: ClassVar[ArrayField]
56 changes: 12 additions & 44 deletions django-stubs/contrib/postgres/fields/ranges.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Literal
from typing import Any, ClassVar, Literal

from django.db import models
from django.db.models.lookups import PostgresOperatorLookup
Expand Down Expand Up @@ -43,68 +43,36 @@ class DateTimeRangeField(RangeField):
class DateRangeField(RangeField):
def __get__(self, instance: Any, owner: Any) -> DateRange: ...

class DateTimeRangeContains(PostgresOperatorLookup):
lookup_name: str
postgres_operator: str
class DateTimeRangeContains(PostgresOperatorLookup): ...

class RangeContainedBy(PostgresOperatorLookup):
lookup_name: str
type_mapping: dict[str, str]
postgres_operator: str

class FullyLessThan(PostgresOperatorLookup):
lookup_name: str
postgres_operator: str

class FullGreaterThan(PostgresOperatorLookup):
lookup_name: str
postgres_operator: str

class NotLessThan(PostgresOperatorLookup):
lookup_name: str
postgres_operator: str

class NotGreaterThan(PostgresOperatorLookup):
lookup_name: str
postgres_operator: str

class AdjacentToLookup(PostgresOperatorLookup):
lookup_name: str
postgres_operator: str
class FullyLessThan(PostgresOperatorLookup): ...
class FullGreaterThan(PostgresOperatorLookup): ...
class NotLessThan(PostgresOperatorLookup): ...
class NotGreaterThan(PostgresOperatorLookup): ...
class AdjacentToLookup(PostgresOperatorLookup): ...

class RangeStartsWith(models.Transform):
lookup_name: str
function: str
@property
def output_field(self) -> models.Field: ...

class RangeEndsWith(models.Transform):
lookup_name: str
function: str
@property
def output_field(self) -> models.Field: ...

class IsEmpty(models.Transform):
lookup_name: str
function: str
output_field: models.BooleanField
output_field: ClassVar[models.BooleanField]

class LowerInclusive(models.Transform):
lookup_name: str
function: str
output_field: models.BooleanField
output_field: ClassVar[models.BooleanField]

class LowerInfinite(models.Transform):
lookup_name: str
function: str
output_field: models.BooleanField
output_field: ClassVar[models.BooleanField]

class UpperInclusive(models.Transform):
lookup_name: str
function: str
output_field: models.BooleanField
output_field: ClassVar[models.BooleanField]

class UpperInfinite(models.Transform):
lookup_name: str
function: str
output_field: models.BooleanField
output_field: ClassVar[models.BooleanField]
11 changes: 8 additions & 3 deletions django-stubs/contrib/postgres/functions.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.db.models import Func
from typing import ClassVar

class RandomUUID(Func): ...
class TransactionNow(Func): ...
from django.db.models import DateTimeField, Func, UUIDField

class RandomUUID(Func):
output_field: ClassVar[UUIDField]

class TransactionNow(Func):
output_field: ClassVar[DateTimeField]
Loading