Skip to content

Commit

Permalink
5.0: Update django.contrib.postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
sudosubin committed Apr 20, 2024
1 parent 13390d5 commit 1e2eda0
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 137 deletions.
1 change: 1 addition & 0 deletions django-stubs/contrib/postgres/aggregates/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .general import ArrayAgg as ArrayAgg
from .general import BitAnd as BitAnd
from .general import BitOr as BitOr
from .general import BitXor as BitXor
from .general import BoolAnd as BoolAnd
from .general import BoolOr as BoolOr
from .general import JSONBAgg as JSONBAgg
Expand Down
38 changes: 37 additions & 1 deletion django-stubs/contrib/postgres/aggregates/general.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
from typing import ClassVar
from typing import Any, ClassVar

from django.contrib.postgres.fields import ArrayField
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Aggregate, BooleanField, JSONField, TextField
from django.db.models.expressions import BaseExpression, Combinable
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from typing_extensions import Self

from .mixins import OrderableAggMixin

class ArrayAgg(OrderableAggMixin, Aggregate):
@property
def output_field(self) -> ArrayField: ...
def resolve_expression(
self,
query: Any = ...,
allow_joins: bool = ...,
reuse: set[str] | None = ...,
summarize: bool = ...,
for_save: bool = ...,
) -> Self: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]

class BitAnd(Aggregate): ...
class BitOr(Aggregate): ...
class BitXor(Aggregate): ...

class BoolAnd(Aggregate):
output_field: ClassVar[BooleanField]
Expand All @@ -20,6 +34,28 @@ class BoolOr(Aggregate):

class JSONBAgg(OrderableAggMixin, Aggregate):
output_field: ClassVar[JSONField]
def __init__(
self, *expressions: BaseExpression | Combinable | str, default: Any | None = ..., **extra: Any
) -> None: ...
def resolve_expression(
self,
query: Any = ...,
allow_joins: bool = ...,
reuse: set[str] | None = ...,
summarize: bool = ...,
for_save: bool = ...,
) -> Self: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]

class StringAgg(OrderableAggMixin, Aggregate):
output_field: ClassVar[TextField]
def __init__(self, expression: BaseExpression | Combinable | str, delimiter: Any, **extra: Any) -> None: ...
def resolve_expression(
self,
query: Any = ...,
allow_joins: bool = ...,
reuse: set[str] | None = ...,
summarize: bool = ...,
for_save: bool = ...,
) -> Self: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]
18 changes: 17 additions & 1 deletion django-stubs/contrib/postgres/aggregates/mixins.pyi
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
class OrderableAggMixin: ...
from collections.abc import Sequence
from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.expressions import BaseExpression, Combinable, Expression, OrderByList
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from typing_extensions import Self

class OrderableAggMixin:
order_by: OrderByList
def __init__(
self, *expressions: BaseExpression | Combinable | str, ordering: Sequence[str] = ..., **extra: Any
) -> None: ...
def resolve_expression(self, *args: Any, **kwargs: Any) -> Self: ...
def get_source_expressions(self) -> list[Expression]: ...
def set_source_expressions(self, exprs: Sequence[Combinable]) -> None: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ...
12 changes: 10 additions & 2 deletions django-stubs/contrib/postgres/aggregates/statistics.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from typing import ClassVar
from typing import Any, ClassVar

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

class StatAggregate(Aggregate):
output_field: ClassVar[FloatField]
def __init__(
self, y: Any, x: Any, output_field: Any | None = ..., filter: Any | None = ..., default: Any | None = ...
) -> None: ...

class Corr(StatAggregate): ...
class CovarPop(StatAggregate): ...

class CovarPop(StatAggregate):
def __init__(
self, y: Any, x: Any, sample: bool = ..., filter: Any | None = ..., default: Any | None = ...
) -> None: ...

class RegrAvgX(StatAggregate): ...
class RegrAvgY(StatAggregate): ...

Expand Down
13 changes: 11 additions & 2 deletions django-stubs/contrib/postgres/constraints.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from collections.abc import Sequence
from collections.abc import Iterable, Sequence

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.models import Deferrable
from django.db.models.base import Model
from django.db.models.constraints import BaseConstraint
from django.db.models.expressions import Combinable
from django.db.models.indexes import IndexExpression
from django.db.models.query_utils import Q
from django.utils.functional import _StrOrPromise

class ExclusionConstraintExpression(IndexExpression): ...

class ExclusionConstraint(BaseConstraint):
template: str
expressions: Sequence[tuple[str | Combinable, str]]
index_type: str
condition: Q | None
Expand All @@ -19,7 +25,10 @@ class ExclusionConstraint(BaseConstraint):
condition: Q | None = ...,
deferrable: Deferrable | None = ...,
include: list[str] | tuple[str] | None = ...,
opclasses: list[str] | tuple[str] = ...,
violation_error_code: str | None = ...,
violation_error_message: _StrOrPromise | None = ...,
) -> None: ...
def check_supported(self, schema_editor: BaseDatabaseSchemaEditor) -> None: ...
def validate(
self, model: type[Model], instance: Model, exclude: Iterable[str] | None = ..., using: str = ...
) -> None: ...
9 changes: 7 additions & 2 deletions django-stubs/contrib/postgres/fields/array.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from collections.abc import Iterable, Sequence
from typing import Any, TypeVar

from _typeshed import Unused
from django.core.validators import _ValidatorCallable
from django.db.models import Field, Transform
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Field
from django.db.models.expressions import Combinable, Expression
from django.db.models.fields import NOT_PROVIDED, _ErrorMessagesDict, _ErrorMessagesMapping
from django.db.models.fields.mixins import CheckFieldDefaultMixin
from django.db.models.lookups import Transform
from django.utils.choices import _Choices
from django.utils.functional import _StrOrPromise

Expand Down Expand Up @@ -55,4 +58,6 @@ class ArrayField(CheckFieldDefaultMixin, Field[_ST, _GT]):
) -> None: ...
@property
def description(self) -> str: ... # type: ignore[override]
def get_transform(self, name: Any) -> type[Transform] | None: ...
def cast_db_type(self, connection: BaseDatabaseWrapper) -> str: ...
def get_placeholder(self, value: Unused, compiler: Unused, connection: BaseDatabaseWrapper) -> str: ...
def get_transform(self, name: str) -> type[Transform] | None: ...
6 changes: 5 additions & 1 deletion django-stubs/contrib/postgres/fields/citext.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.fields import CharField, EmailField, TextField

class CIText: ...
class CIText:
def get_internal_type(self) -> str: ...
def db_type(self, connection: BaseDatabaseWrapper) -> str: ...

class CICharField(CIText, CharField): ...
class CIEmailField(CIText, EmailField): ...
class CITextField(CIText, TextField): ...
3 changes: 3 additions & 0 deletions django-stubs/contrib/postgres/fields/hstore.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Any, ClassVar

from django.contrib.postgres.fields.array import ArrayField
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Field, TextField, Transform
from django.db.models.fields.mixins import CheckFieldDefaultMixin
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType

class HStoreField(CheckFieldDefaultMixin, Field):
def get_transform(self, name: str) -> Any: ...
Expand All @@ -11,6 +13,7 @@ class KeyTransform(Transform):
output_field: ClassVar[TextField]

def __init__(self, key_name: str, *args: Any, **kwargs: Any) -> None: ...
def as_sql(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]

class KeyTransformFactory:
def __init__(self, key_name: str) -> None: ...
Expand Down
5 changes: 0 additions & 5 deletions django-stubs/contrib/postgres/fields/jsonb.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from django.db.models import JSONField as BuiltinJSONField
from django.db.models.fields.json import KeyTextTransform as BuiltinKeyTextTransform
from django.db.models.fields.json import KeyTransform as BuiltinKeyTransform

# All deprecated
class JSONField(BuiltinJSONField): ...
class KeyTransform(BuiltinKeyTransform): ...
class KeyTextTransform(BuiltinKeyTextTransform): ...
41 changes: 27 additions & 14 deletions django-stubs/contrib/postgres/fields/ranges.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from typing import Any, ClassVar, Literal
from typing import Any, ClassVar, Literal, TypeVar

from _typeshed import Unused
from django.contrib.postgres import forms
from django.db import models
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.lookups import PostgresOperatorLookup
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange, Range # type: ignore [import-untyped]

class RangeBoundary(models.Expression):
Expand All @@ -21,32 +25,41 @@ class RangeOperators:
NOT_GT: Literal["&<"]
ADJACENT_TO: Literal["-|-"]

class RangeField(models.Field):
_Range = TypeVar("_Range", bound=Range[Any])

class RangeField(models.Field[Any, _Range]):
empty_strings_allowed: bool
base_field: models.Field
range_type: type[Range]
base_field: type[models.Field]
range_type: type[_Range]
def get_prep_value(self, value: Any) -> Any | None: ...
def get_placeholder(self, value: Unused, compiler: Unused, connection: BaseDatabaseWrapper) -> str: ...
def to_python(self, value: Any) -> Any: ...

class IntegerRangeField(RangeField):
def __get__(self, instance: Any, owner: Any) -> NumericRange: ...
class IntegerRangeField(RangeField[NumericRange]):
base_field: type[models.IntegerField]
form_field: type[forms.IntegerRangeField]

class BigIntegerRangeField(RangeField):
def __get__(self, instance: Any, owner: Any) -> NumericRange: ...
class BigIntegerRangeField(RangeField[NumericRange]):
base_field: type[models.BigIntegerField]
form_field: type[forms.IntegerRangeField]

class DecimalRangeField(RangeField):
def __get__(self, instance: Any, owner: Any) -> NumericRange: ...
class DecimalRangeField(RangeField[NumericRange]):
base_field: type[models.DecimalField]
form_field: type[forms.DecimalRangeField]

class DateTimeRangeField(RangeField):
def __get__(self, instance: Any, owner: Any) -> DateTimeTZRange: ...
class DateTimeRangeField(RangeField[DateTimeTZRange]):
base_field: type[models.DecimalField]
form_field: type[forms.DecimalRangeField]

class DateRangeField(RangeField):
def __get__(self, instance: Any, owner: Any) -> DateRange: ...
class DateRangeField(RangeField[DateRange]):
base_field: type[models.DateField]
form_field: type[forms.DateRangeField]

class DateTimeRangeContains(PostgresOperatorLookup): ...

class RangeContainedBy(PostgresOperatorLookup):
type_mapping: dict[str, str]
def process_lhs(self, compiler: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]

class FullyLessThan(PostgresOperatorLookup): ...
class FullGreaterThan(PostgresOperatorLookup): ...
Expand Down
15 changes: 11 additions & 4 deletions django-stubs/contrib/postgres/forms/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from .array import *
from .hstore import *
from .jsonb import *
from .ranges import *
from .array import SimpleArrayField as SimpleArrayField
from .array import SplitArrayField as SplitArrayField
from .array import SplitArrayWidget as SplitArrayWidget
from .hstore import HStoreField as HStoreField
from .ranges import BaseRangeField as BaseRangeField
from .ranges import DateRangeField as DateRangeField
from .ranges import DateTimeRangeField as DateTimeRangeField
from .ranges import DecimalRangeField as DecimalRangeField
from .ranges import HiddenRangeWidget as HiddenRangeWidget
from .ranges import IntegerRangeField as IntegerRangeField
from .ranges import RangeWidget as RangeWidget
7 changes: 0 additions & 7 deletions django-stubs/contrib/postgres/forms/jsonb.pyi

This file was deleted.

7 changes: 6 additions & 1 deletion django-stubs/contrib/postgres/lookups.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Transform
from django.db.models.lookups import PostgresOperatorLookup
from django.db.models.sql.compiler import SQLCompiler, _AsSqlType

from .search import SearchVectorExact

Expand All @@ -10,7 +12,10 @@ class HasKey(PostgresOperatorLookup): ...
class HasKeys(PostgresOperatorLookup): ...
class HasAnyKeys(HasKeys): ...
class Unaccent(Transform): ...
class SearchLookup(SearchVectorExact): ...

class SearchLookup(SearchVectorExact):
def process_lhs(self, qn: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ... # type: ignore[override]

class TrigramSimilar(PostgresOperatorLookup): ...
class TrigramWordSimilar(PostgresOperatorLookup): ...
class TrigramStrictWordSimilar(PostgresOperatorLookup): ...
28 changes: 27 additions & 1 deletion django-stubs/contrib/postgres/search.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from typing import Any, ClassVar

from django.db.backends.base.base import BaseDatabaseWrapper
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 django.db.models.sql.compiler import SQLCompiler, _AsSqlType
from typing_extensions import Self, TypeAlias

_Expression: TypeAlias = str | Combinable | SearchQueryCombinable

class SearchVectorExact(Lookup): ...
class SearchVectorExact(Lookup):
def process_rhs(self, qn: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ...
def as_sql(self, qn: SQLCompiler, connection: BaseDatabaseWrapper) -> _AsSqlType: ...

class SearchVectorField(Field): ...
class SearchQueryField(Field): ...

Expand All @@ -28,6 +33,13 @@ class SearchVector(SearchVectorCombinable, Func):
def __init__(
self, *expressions: _Expression, config: _Expression | None = ..., weight: Any | None = ...
) -> None: ...
def as_sql( # type: ignore[override]
self,
compiler: SQLCompiler,
connection: BaseDatabaseWrapper,
function: str | None = ...,
template: str | None = ...,
) -> _AsSqlType: ...

class CombinedSearchVector(SearchVectorCombinable, CombinedExpression):
def __init__(
Expand Down Expand Up @@ -59,6 +71,13 @@ class SearchQuery(SearchQueryCombinable, Func): # type: ignore[misc]
invert: bool = ...,
search_type: str = ...,
) -> None: ...
def as_sql( # type: ignore[override]
self,
compiler: SQLCompiler,
connection: BaseDatabaseWrapper,
function: str | None = ...,
template: str | None = ...,
) -> _AsSqlType: ...
def __invert__(self) -> Self: ... # type: ignore[override]

class CombinedSearchQuery(SearchQueryCombinable, CombinedExpression): # type: ignore[misc]
Expand Down Expand Up @@ -101,6 +120,13 @@ class SearchHeadline(Func):
max_fragments: int | None = ...,
fragment_delimiter: str | None = ...,
) -> None: ...
def as_sql( # type: ignore[override]
self,
compiler: SQLCompiler,
connection: BaseDatabaseWrapper,
function: str | None = ...,
template: str | None = ...,
) -> _AsSqlType: ...

class TrigramBase(Func):
output_field: ClassVar[FloatField]
Expand Down
5 changes: 3 additions & 2 deletions django-stubs/contrib/postgres/signals.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any

def get_hstore_oids(connection_alias: str) -> tuple[Any, ...]: ...
def get_citext_oids(connection_alias: str) -> tuple[Any, ...]: ...
def get_type_oids(connection_alias: str, type_name: str) -> tuple[tuple[Any, ...], tuple[Any, ...]]: ...
def get_hstore_oids(connection_alias: str) -> tuple[tuple[Any, ...], tuple[Any, ...]]: ...
def get_citext_oids(connection_alias: str) -> tuple[tuple[Any, ...], tuple[Any, ...]]: ...
def register_type_handlers(connection: Any, **kwargs: Any) -> None: ...
1 change: 1 addition & 0 deletions django-stubs/db/models/aggregates.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Aggregate(Func):
filter_template: str
filter: Any
allow_distinct: bool
empty_result_set_value: int | None
def __init__(self, *expressions: Any, distinct: bool = ..., filter: Any | None = ..., **extra: Any) -> None: ...

class Avg(FixDurationInputMixin, NumericOutputFieldMixin, Aggregate): ...
Expand Down
Loading

0 comments on commit 1e2eda0

Please sign in to comment.