From 159f8b95ba28a091f9ca4006b106099d5e793949 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 19 Jan 2021 22:13:36 +0300 Subject: [PATCH 1/2] add django 3.1 jsonfield --- django-stubs/db/models/__init__.pyi | 1 + django-stubs/db/models/fields/json.pyi | 100 +++++-------------------- django-stubs/db/models/lookups.pyi | 2 +- 3 files changed, 21 insertions(+), 82 deletions(-) diff --git a/django-stubs/db/models/__init__.pyi b/django-stubs/db/models/__init__.pyi index 1e10126..823a14c 100644 --- a/django-stubs/db/models/__init__.pyi +++ b/django-stubs/db/models/__init__.pyi @@ -60,6 +60,7 @@ from .fields.files import ( FileDescriptor as FileDescriptor, ) from .fields.proxy import OrderWrt as OrderWrt +from .fields.json import JSONField as JSONField from .deletion import ( CASCADE as CASCADE, diff --git a/django-stubs/db/models/fields/json.pyi b/django-stubs/db/models/fields/json.pyi index a1dd4b3..0af4f75 100644 --- a/django-stubs/db/models/fields/json.pyi +++ b/django-stubs/db/models/fields/json.pyi @@ -2,103 +2,43 @@ from . import Field from .mixins import CheckFieldDefaultMixin from django.db.models import lookups from django.db.models.lookups import PostgresOperatorLookup, Transform -from typing import Any, Optional +from typing import Any, Optional, Callable + class JSONField(CheckFieldDefaultMixin, Field): - empty_strings_allowed: bool = ... - description: Any = ... - default_error_messages: Any = ... - encoder: Any = ... - decoder: Any = ... def __init__( self, - verbose_name: Optional[Any] = ..., - name: Optional[Any] = ..., - encoder: Optional[Any] = ..., - decoder: Optional[Any] = ..., + verbose_name: Optional[str] = ..., + name: Optional[str] = ..., + encoder: Optional[Callable] = ..., + decoder: Optional[Callable] = ..., **kwargs: Any ) -> None: ... - def check(self, **kwargs: Any): ... - def deconstruct(self): ... - def from_db_value(self, value: Any, expression: Any, connection: Any): ... - def get_internal_type(self): ... - def get_prep_value(self, value: Any): ... - def get_transform(self, name: Any): ... - def validate(self, value: Any, model_instance: Any) -> None: ... def value_to_string(self, obj: Any): ... - def formfield(self, **kwargs: Any): ... -class DataContains(PostgresOperatorLookup): - lookup_name: str = ... - postgres_operator: str = ... - def as_sql(self, compiler: Any, connection: Any): ... +class DataContains(PostgresOperatorLookup): ... +class ContainedBy(PostgresOperatorLookup): ... -class ContainedBy(PostgresOperatorLookup): - lookup_name: str = ... - postgres_operator: str = ... - def as_sql(self, compiler: Any, connection: Any): ... - -class HasKeyLookup(PostgresOperatorLookup): - logical_operator: Any = ... - def as_sql(self, compiler: Any, connection: Any, template: Optional[Any] = ...): ... - def as_mysql(self, compiler: Any, connection: Any): ... - def as_oracle(self, compiler: Any, connection: Any): ... - lhs: Any = ... - rhs: Any = ... - def as_postgresql(self, compiler: Any, connection: Any): ... - def as_sqlite(self, compiler: Any, connection: Any): ... - -class HasKey(HasKeyLookup): - lookup_name: str = ... - postgres_operator: str = ... - prepare_rhs: bool = ... - -class HasKeys(HasKeyLookup): - lookup_name: str = ... - postgres_operator: str = ... - logical_operator: str = ... - def get_prep_lookup(self): ... - -class HasAnyKeys(HasKeys): - lookup_name: str = ... - postgres_operator: str = ... - logical_operator: str = ... - -class JSONExact(lookups.Exact): - can_use_none_as_rhs: bool = ... - def process_rhs(self, compiler: Any, connection: Any): ... +class HasKeyLookup(PostgresOperatorLookup): ... +class HasKey(HasKeyLookup): ... +class HasKeys(HasKeyLookup): ... +class HasAnyKeys(HasKeys): ... +class JSONExact(lookups.Exact): ... class KeyTransform(Transform): - postgres_operator: str = ... - postgres_nested_operator: str = ... key_name: Any = ... def __init__(self, key_name: Any, *args: Any, **kwargs: Any) -> None: ... def preprocess_lhs(self, compiler: Any, connection: Any, lhs_only: bool = ...): ... - def as_mysql(self, compiler: Any, connection: Any): ... - def as_oracle(self, compiler: Any, connection: Any): ... - def as_postgresql(self, compiler: Any, connection: Any): ... - -class KeyTextTransform(KeyTransform): - postgres_operator: str = ... - postgres_nested_operator: str = ... +class KeyTextTransform(KeyTransform): ... class KeyTransformTextLookupMixin: def __init__(self, key_transform: Any, *args: Any, **kwargs: Any) -> None: ... -class CaseInsensitiveMixin: - def process_rhs(self, compiler: Any, connection: Any): ... - -class KeyTransformIsNull(lookups.IsNull): - def as_oracle(self, compiler: Any, connection: Any): ... - def as_sqlite(self, compiler: Any, connection: Any): ... - -class KeyTransformIn(lookups.In): - def process_rhs(self, compiler: Any, connection: Any): ... - -class KeyTransformExact(JSONExact): - def process_rhs(self, compiler: Any, connection: Any): ... - def as_oracle(self, compiler: Any, connection: Any): ... +class CaseInsensitiveMixin: ... +class KeyTransformIsNull(lookups.IsNull): ... +class KeyTransformIn(lookups.In): ... +class KeyTransformExact(JSONExact): ... class KeyTransformIExact(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IExact): ... class KeyTransformIContains(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IContains): ... class KeyTransformStartsWith(KeyTransformTextLookupMixin, lookups.StartsWith): ... @@ -108,9 +48,7 @@ class KeyTransformIEndsWith(CaseInsensitiveMixin, KeyTransformTextLookupMixin, l class KeyTransformRegex(KeyTransformTextLookupMixin, lookups.Regex): ... class KeyTransformIRegex(CaseInsensitiveMixin, KeyTransformTextLookupMixin, lookups.IRegex): ... -class KeyTransformNumericLookupMixin: - def process_rhs(self, compiler: Any, connection: Any): ... - +class KeyTransformNumericLookupMixin: ... class KeyTransformLt(KeyTransformNumericLookupMixin, lookups.LessThan): ... class KeyTransformLte(KeyTransformNumericLookupMixin, lookups.LessThanOrEqual): ... class KeyTransformGt(KeyTransformNumericLookupMixin, lookups.GreaterThan): ... diff --git a/django-stubs/db/models/lookups.pyi b/django-stubs/db/models/lookups.pyi index d418db5..ca9ab66 100644 --- a/django-stubs/db/models/lookups.pyi +++ b/django-stubs/db/models/lookups.pyi @@ -60,7 +60,7 @@ class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin): ) -> Any: ... class PostgresOperatorLookup(FieldGetDbPrepValueMixin, Lookup): - postgres_operator: Any = ... + postgres_operator: str = ... def as_postgresql(self, compiler: Any, connection: Any): ... class Exact(FieldGetDbPrepValueMixin, BuiltinLookup): ... From 11c3f8cd11a33a4e16ab207bb835285de5d7ed29 Mon Sep 17 00:00:00 2001 From: Maksim Kurnikov Date: Tue, 19 Jan 2021 22:16:12 +0300 Subject: [PATCH 2/2] add django 3.1 classproperty --- django-stubs/utils/decorators.pyi | 8 ++------ django-stubs/utils/functional.pyi | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/django-stubs/utils/decorators.pyi b/django-stubs/utils/decorators.pyi index 3badf23..704213d 100644 --- a/django-stubs/utils/decorators.pyi +++ b/django-stubs/utils/decorators.pyi @@ -3,6 +3,8 @@ from typing import Any, Callable, Iterable, Optional, Type, Union, TypeVar from django.utils.deprecation import MiddlewareMixin from django.views.generic.base import View +from django.utils.functional import classproperty as classproperty + _T = TypeVar("_T", bound=Union[View, Callable]) # Any callable class classonlymethod(classmethod): ... @@ -12,9 +14,3 @@ def decorator_from_middleware_with_args(middleware_class: type) -> Callable: ... def decorator_from_middleware(middleware_class: type) -> Callable: ... def available_attrs(fn: Callable): ... def make_middleware_decorator(middleware_class: Type[MiddlewareMixin]) -> Callable: ... - -class classproperty: - fget: Optional[Callable] = ... - def __init__(self, method: Optional[Callable] = ...) -> None: ... - def __get__(self, instance: Any, cls: Optional[type] = ...) -> Any: ... - def getter(self, method: Callable) -> classproperty: ... diff --git a/django-stubs/utils/functional.pyi b/django-stubs/utils/functional.pyi index 7fa7aba..954e23d 100644 --- a/django-stubs/utils/functional.pyi +++ b/django-stubs/utils/functional.pyi @@ -61,3 +61,9 @@ _PartitionMember = TypeVar("_PartitionMember") def partition( predicate: Callable, values: List[_PartitionMember] ) -> Tuple[List[_PartitionMember], List[_PartitionMember]]: ... + +class classproperty: + fget: Optional[Callable] = ... + def __init__(self, method: Optional[Callable] = ...) -> None: ... + def __get__(self, instance: Any, cls: Optional[type] = ...) -> Any: ... + def getter(self, method: Callable) -> classproperty: ...