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
45 changes: 24 additions & 21 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 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 Down Expand Up @@ -32,37 +35,37 @@ class Area(OracleToleranceMixin, GeoFunc):
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]
12 changes: 8 additions & 4 deletions django-stubs/contrib/postgres/search.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any
from typing import Any, ClassVar

from django.db.models import Expression, Field
from django.db.models import Expression, Field, FloatField, TextField
from django.db.models.expressions import Combinable, CombinedExpression, Func
from django.db.models.lookups import Lookup
from typing_extensions import Self, TypeAlias
Expand All @@ -24,7 +24,7 @@ class SearchVector(SearchVectorCombinable, Func):
config: _Expression | None
function: str
arg_joiner: str
output_field: Field
output_field: ClassVar[SearchVectorField]
def __init__(
self, *expressions: _Expression, config: _Expression | None = ..., weight: Any | None = ...
) -> None: ...
Expand All @@ -48,6 +48,7 @@ class SearchQueryCombinable:
def __rand__(self, other: SearchQueryCombinable) -> Self: ...

class SearchQuery(SearchQueryCombinable, Func): # type: ignore[misc]
output_field: ClassVar[SearchQueryField]
SEARCH_TYPES: dict[str, str]
def __init__(
self,
Expand All @@ -71,6 +72,7 @@ class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: i
) -> None: ...

class SearchRank(Func):
output_field: ClassVar[FloatField]
def __init__(
self,
vector: SearchVector | _Expression,
Expand All @@ -83,7 +85,7 @@ class SearchRank(Func):
class SearchHeadline(Func):
function: str
template: str
output_field: Field
output_field: ClassVar[TextField]
def __init__(
self,
expression: _Expression,
Expand All @@ -101,9 +103,11 @@ class SearchHeadline(Func):
) -> None: ...

class TrigramBase(Func):
output_field: ClassVar[FloatField]
def __init__(self, expression: _Expression, string: str, **extra: Any) -> None: ...

class TrigramWordBase(Func):
output_field: ClassVar[FloatField]
def __init__(self, string: str, expression: _Expression, **extra: Any) -> None: ...

class TrigramSimilarity(TrigramBase): ...
Expand Down
8 changes: 6 additions & 2 deletions django-stubs/db/models/aggregates.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any
from typing import Any, ClassVar

from django.db.models.expressions import Func
from django.db.models.fields import IntegerField
from django.db.models.functions.mixins import FixDurationInputMixin, NumericOutputFieldMixin

class Aggregate(Func):
Expand All @@ -10,7 +11,10 @@ class Aggregate(Func):
def __init__(self, *expressions: Any, distinct: bool = ..., filter: Any | None = ..., **extra: Any) -> None: ...

class Avg(FixDurationInputMixin, NumericOutputFieldMixin, Aggregate): ...
class Count(Aggregate): ...

class Count(Aggregate):
output_field: ClassVar[IntegerField]

class Max(Aggregate): ...
class Min(Aggregate): ...
class StdDev(NumericOutputFieldMixin, Aggregate): ...
Expand Down
Loading