diff --git a/django-stubs/contrib/postgres/fields/array.pyi b/django-stubs/contrib/postgres/fields/array.pyi index 472e90b67..c0f64734b 100644 --- a/django-stubs/contrib/postgres/fields/array.pyi +++ b/django-stubs/contrib/postgres/fields/array.pyi @@ -1,22 +1,18 @@ from typing import ( Any, + Callable, Generic, Iterable, List, Optional, - Sequence, + Tuple, TypeVar, Union, overload, ) from django.db.models.expressions import Combinable -from django.db.models.fields import ( - Field, - _ErrorMessagesToOverride, - _FieldChoices, - _ValidatorCallable, -) +from django.db.models.fields import Field, _ErrorMessagesToOverride, _ValidatorCallable from typing_extensions import Literal from .mixins import CheckFieldDefaultMixin @@ -26,7 +22,7 @@ _T = TypeVar("_T", bound=Optional[List[Any]]) class ArrayField( Generic[_T], CheckFieldDefaultMixin, - Field[Union[Sequence[Any], Combinable], List[Any]], + Field[Union[_T, Combinable], _T], ): empty_strings_allowed: bool = ... @@ -36,11 +32,11 @@ class ArrayField( default_validators: Any = ... from_db_value: Any = ... @overload - def __new__( # type: ignore [misc] - cls, + def __init__( + self: ArrayField[List[Any]], base_field: Field[Any, Any], size: Optional[int] = ..., - verbose_name: Optional[Union[str, bytes]] = ..., + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -48,26 +44,28 @@ class ArrayField( blank: bool = ..., null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_T, Callable[[], _T]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_T, str], Tuple[str, Iterable[Tuple[_T, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> ArrayField[List[Any]]: ... + ) -> None: ... @overload - def __new__( - cls, + def __init__( + self: ArrayField[Optional[List[Any]]], base_field: Field[Any, Any], size: Optional[int] = ..., - verbose_name: Optional[Union[str, bytes]] = ..., + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -75,22 +73,54 @@ class ArrayField( blank: bool = ..., null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_T, Callable[[], _T]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_T, str], Tuple[str, Iterable[Tuple[_T, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + ) -> None: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> ArrayField[List[Any]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, ) -> ArrayField[Optional[List[Any]]]: ... - def __get__(self: ArrayField[_T], instance: Any, owner: Any) -> _T: ... # type: ignore [override] - def __set__(self: ArrayField[_T], instance: Any, value: _T) -> None: ... # type: ignore [override] + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_T, str], Tuple[str, Iterable[Tuple[_T, str]]]]], + **kwargs: Any, + ) -> ArrayField[_T]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_T, str], Tuple[str, Iterable[Tuple[_T, str]]]]], + **kwargs: Any, + ) -> ArrayField[Optional[_T]]: ... @property def description(self) -> str: ... # type: ignore [override] def get_transform(self, name: Any) -> Any: ... diff --git a/django-stubs/db/models/fields/__init__.pyi b/django-stubs/db/models/fields/__init__.pyi index f95cf76d3..a36e41069 100644 --- a/django-stubs/db/models/fields/__init__.pyi +++ b/django-stubs/db/models/fields/__init__.pyi @@ -1,4 +1,5 @@ import decimal +import ipaddress import uuid from datetime import date, datetime, time, timedelta from typing import ( @@ -26,11 +27,9 @@ from django.forms import Field as FormField from django.forms import Widget from typing_extensions import Literal -class NOT_PROVIDED: ... - BLANK_CHOICE_DASH: List[Tuple[str, str]] = ... -_Choice = Tuple[Any, Any] +_Choice = Tuple[Any, str] _ChoiceNamedGroup = Tuple[str, Iterable[_Choice]] _FieldChoices = Iterable[Union[_Choice, _ChoiceNamedGroup]] @@ -39,9 +38,42 @@ _ErrorMessagesToOverride = Dict[str, Any] _T = TypeVar("_T", bound="Field[Any, Any]") # __set__ value type -_ST = TypeVar("_ST") +_ST = TypeVar("_ST", contravariant=True) # __get__ return type -_GT = TypeVar("_GT") +_GT = TypeVar("_GT", covariant=True) + +class NOT_PROVIDED: ... + +# NOTE: Some info regarding __init__ and __new__ for all Field subclasses: +# +# - __init__: Field.__init__ provides arguments validation and completion for pratically all +# available arguments for all fields. Subclasses should only define theirs if they expect +# different arguments (e.g. DecimalField expects max_digits and decimal_places) +# +# - __new__: All subclasses should define at least 2: +# +# - One for `null: Literal[False] = ...`, which should return its type with the generic +# _ST and _GT mapping to the proper type (e.g. IntegerField would return IntegerField[int]) +# +# - One for `null: Literal[True]`, which should return its type with the generic +# _ST and _GT mapping to the proper type being optional (e.g. IntegerField would +# return IntegerField[Optional[int]]) +# +# Also, the subclass can define 2 more to capture the fields on choices to make the typing +# respect the available choices for __get__ and __set__. They both should define choices as: +# `choices: Iterable[Union[Tuple[, str], Tuple[str, Iterable[Tuple[, str]]]]]`: +# +# - One with choices and `null: Literal[False] = ...`. This means that the previous one +# should set `choices: None = ...`. +# +# - One with choices and `null: Literal[True]`. This means that the previous one +# should set `choices: None = ...`. +# +# Also note that __new__ doesn't have to define all available args as it is __init__'s +# responsability of doing so. Instead it can only define the required arguments to define +# the generic typing together with `*args: Any` and `**kwargs: Any`. +# +# In doubt, look in this file for some examples. class Field(RegisterLookupMixin, Generic[_ST, _GT]): @@ -120,29 +152,27 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]): def cached_col(self) -> Col: ... def value_from_object(self, obj: Model) -> _GT: ... def get_attname(self) -> str: ... - -_I = TypeVar("_I", bound=Optional[int]) - -class IntegerField(Generic[_I], Field[Union[float, int, str, Combinable], int]): @overload def __init__( - self: IntegerField[int], - verbose_name: Optional[Union[str, bytes]] = ..., + self, + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., unique: bool = ..., blank: bool = ..., - null: Literal[False] = ..., + null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_GT, Callable[[], _GT]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_GT, str], Tuple[str, Iterable[Tuple[_GT, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., @@ -151,44 +181,287 @@ class IntegerField(Generic[_I], Field[Union[float, int, str, Combinable], int]): ) -> None: ... @overload def __init__( - self: IntegerField[Optional[int]], - verbose_name: Optional[Union[str, bytes]] = ..., + self, + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., unique: bool = ..., blank: bool = ..., - null: Literal[True] = ..., + null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_GT, Callable[[], _GT]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_GT, str], Tuple[str, Iterable[Tuple[_GT, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., ) -> None: ... - def __get__(self: IntegerField[_I], instance: Any, owner: Any) -> _I: ... # type: ignore [override] - def __set__( - self: IntegerField[_I], - instance: Any, - value: Union[str, float, int, Combinable, _I], - ) -> None: ... + +_I = TypeVar("_I", bound=Optional[int]) + +class IntegerField(Generic[_I], Field[Union[_I, Combinable], _I]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> IntegerField[int]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> IntegerField[Optional[int]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> IntegerField[_I]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> IntegerField[Optional[_I]]: ... class PositiveIntegerRelDbTypeMixin: def rel_db_type(self, connection: Any) -> Any: ... class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> PositiveIntegerField[int]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> PositiveIntegerField[Optional[int]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> PositiveIntegerField[_I]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> PositiveIntegerField[Optional[_I]]: ... + +class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> PositiveSmallIntegerField[int]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> PositiveSmallIntegerField[Optional[int]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> PositiveSmallIntegerField[_I]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> PositiveSmallIntegerField[Optional[_I]]: ... + +class SmallIntegerField(IntegerField[_I]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> SmallIntegerField[int]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> SmallIntegerField[Optional[int]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> SmallIntegerField[_I]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> SmallIntegerField[Optional[_I]]: ... + +class BigIntegerField(IntegerField[_I]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> BigIntegerField[int]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> BigIntegerField[Optional[int]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> BigIntegerField[_I]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> BigIntegerField[Optional[_I]]: ... + +class PositiveBigIntegerField(IntegerField[_I]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> PositiveBigIntegerField[int]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> PositiveBigIntegerField[Optional[int]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> PositiveBigIntegerField[_I]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_I, str], Tuple[str, Iterable[Tuple[_I, str]]]]], + **kwargs: Any, + ) -> PositiveBigIntegerField[Optional[_I]]: ... + +_F = TypeVar("_F", bound=Optional[float]) + +class FloatField(Generic[_F], Field[Union[_F, Combinable], _F]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> FloatField[float]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> FloatField[Optional[float]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_F, str], Tuple[str, Iterable[Tuple[_F, str]]]]], + **kwargs: Any, + ) -> FloatField[_F]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_F, str], Tuple[str, Iterable[Tuple[_F, str]]]]], + **kwargs: Any, + ) -> FloatField[Optional[_F]]: ... + +_DEC = TypeVar("_DEC", bound=Optional[decimal.Decimal]) + +class DecimalField(Generic[_DEC], Field[Union[_DEC, Combinable], _DEC]): + # attributes + max_digits: int = ... + decimal_places: int = ... @overload def __init__( - self: PositiveIntegerField[int], - verbose_name: Optional[Union[str, bytes]] = ..., + self: DecimalField[decimal.Decimal], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -196,24 +469,31 @@ class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): blank: bool = ..., null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_DEC, Callable[[], _DEC]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_DEC, str], Tuple[str, Iterable[Tuple[_DEC, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., + *, + max_digits: int, + decimal_places: int, ) -> None: ... @overload def __init__( - self: PositiveIntegerField[Optional[int]], - verbose_name: Optional[Union[str, bytes]] = ..., + self: DecimalField[Optional[decimal.Decimal]], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -221,32 +501,367 @@ class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): blank: bool = ..., null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_DEC, Callable[[], _DEC]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_DEC, str], Tuple[str, Iterable[Tuple[_DEC, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., + *, + max_digits: int, + decimal_places: int, ) -> None: ... - def __get__(self: PositiveIntegerField[_I], instance: Any, owner: Any) -> _I: ... # type: ignore [override] - def __set__( - self: PositiveIntegerField[_I], - instance: Any, - value: Union[str, float, int, Combinable, _I], - ) -> None: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> DecimalField[decimal.Decimal]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> DecimalField[Optional[decimal.Decimal]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[ + Union[Tuple[_DEC, str], Tuple[str, Iterable[Tuple[_DEC, str]]]] + ], + **kwargs: Any, + ) -> DecimalField[_DEC]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[ + Union[Tuple[_DEC, str], Tuple[str, Iterable[Tuple[_DEC, str]]]] + ], + **kwargs: Any, + ) -> DecimalField[Optional[_DEC]]: ... -class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]): +class AutoFieldMeta(type): ... +class AutoFieldMixin: ... + +class AutoField(AutoFieldMixin, IntegerField[int], metaclass=AutoFieldMeta): + def __new__(cls, *args: Any, **kwargs: Any) -> AutoField: ... + +class BigAutoField(AutoFieldMixin, BigIntegerField[int]): + def __new__(cls, *args: Any, **kwargs: Any) -> BigAutoField: ... + +class SmallAutoField(AutoFieldMixin, SmallIntegerField[int]): + def __new__(cls, *args: Any, **kwargs: Any) -> SmallAutoField: ... + +_C = TypeVar("_C", bound=Optional[str]) + +class CharField(Generic[_C], Field[Union[_C, Combinable], _C]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> CharField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> CharField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> CharField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> CharField[Optional[_C]]: ... + +class SlugField(CharField[_C]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> SlugField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> SlugField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> SlugField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> SlugField[Optional[_C]]: ... + +class EmailField(CharField[_C]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> EmailField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> EmailField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> EmailField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> EmailField[Optional[_C]]: ... + +class URLField(CharField[_C]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> URLField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> URLField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> URLField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> URLField[Optional[_C]]: ... + +class TextField(CharField[_C]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> TextField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> TextField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> TextField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> TextField[Optional[_C]]: ... + +_B = TypeVar("_B", bound=Optional[bool]) + +class BooleanField(Generic[_B], Field[Union[_B, Combinable], _B]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> BooleanField[bool]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> BooleanField[Optional[bool]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> BooleanField[_B]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> BooleanField[Optional[_B]]: ... + +class IPAddressField(Generic[_C], Field[Union[_C, Combinable], _C]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> IPAddressField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> IPAddressField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> IPAddressField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> IPAddressField[Optional[_C]]: ... + +class GenericIPAddressField( + Generic[_C], + Field[Union[_C, ipaddress.IPv4Address, ipaddress.IPv6Address, Combinable], _C], +): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> GenericIPAddressField[str]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> GenericIPAddressField[Optional[str]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> GenericIPAddressField[_C]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> GenericIPAddressField[Optional[_C]]: ... + +_DD = TypeVar("_DD", bound=Optional[date]) + +class DateTimeCheckMixin: ... + +class DateField(DateTimeCheckMixin, Field[Union[_DD, Combinable], _DD]): + # attributes + auto_now: bool = ... + auto_now_add: bool = ... @overload def __init__( - self: PositiveSmallIntegerField[int], - verbose_name: Optional[Union[str, bytes]] = ..., + self: DateField[date], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -254,24 +869,28 @@ class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]) blank: bool = ..., null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_DD, Callable[[], _DD]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_DD, str], Tuple[str, Iterable[Tuple[_DD, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., ) -> None: ... @overload def __init__( - self: PositiveSmallIntegerField[Optional[int]], - verbose_name: Optional[Union[str, bytes]] = ..., + self: DateField[Optional[date]], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -279,32 +898,71 @@ class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_I]) blank: bool = ..., null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_DD, Callable[[], _DD]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_DD, str], Tuple[str, Iterable[Tuple[_DD, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., ) -> None: ... - def __get__(self: PositiveSmallIntegerField[_I], instance: Any, owner: Any) -> _I: ... # type: ignore [override] - def __set__( - self: PositiveSmallIntegerField[_I], - instance: Any, - value: Union[str, float, int, Combinable, _I], - ) -> None: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> DateField[date]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> DateField[Optional[date]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[ + Union[Tuple[_DD, str], Tuple[str, Iterable[Tuple[_DD, str]]]] + ], + **kwargs: Any, + ) -> DateField[_DD]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[ + Union[Tuple[_DD, str], Tuple[str, Iterable[Tuple[_DD, str]]]] + ], + **kwargs: Any, + ) -> DateField[Optional[_DD]]: ... -class SmallIntegerField(IntegerField[_I]): +_TM = TypeVar("_TM", bound=Optional[time]) + +class TimeField(Generic[_TM], DateTimeCheckMixin, Field[Union[_TM, Combinable], _TM]): + # attributes + auto_now: bool = ... + auto_now_add: bool = ... @overload def __init__( - self: SmallIntegerField[int], - verbose_name: Optional[Union[str, bytes]] = ..., + self: TimeField[time], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -312,24 +970,28 @@ class SmallIntegerField(IntegerField[_I]): blank: bool = ..., null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_TM, Callable[[], _TM]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_TM, str], Tuple[str, Iterable[Tuple[_TM, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., ) -> None: ... @overload def __init__( - self: SmallIntegerField[Optional[int]], - verbose_name: Optional[Union[str, bytes]] = ..., + self: TimeField[Optional[time]], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -337,30 +999,73 @@ class SmallIntegerField(IntegerField[_I]): blank: bool = ..., null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_TM, Callable[[], _TM]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_TM, str], Tuple[str, Iterable[Tuple[_TM, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _I: ... # type: ignore [override] - def __set__( - self, instance: Any, value: Union[str, float, int, Combinable, _I] - ) -> None: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> TimeField[time]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> TimeField[Optional[time]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[ + Union[Tuple[_TM, str], Tuple[str, Iterable[Tuple[_TM, str]]]] + ], + **kwargs: Any, + ) -> TimeField[_TM]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[ + Union[Tuple[_TM, str], Tuple[str, Iterable[Tuple[_TM, str]]]] + ], + **kwargs: Any, + ) -> TimeField[Optional[_TM]]: ... -class BigIntegerField(IntegerField[_I]): +_DT = TypeVar("_DT", bound=Optional[datetime]) + +class DateTimeField( + Generic[_DT], DateTimeCheckMixin, Field[Union[_DT, Combinable], _DT] +): + # attributes + auto_now: bool = ... + auto_now_add: bool = ... @overload def __init__( - self: BigIntegerField[int], - verbose_name: Optional[Union[str, bytes]] = ..., + self: DateTimeField[datetime], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -368,24 +1073,28 @@ class BigIntegerField(IntegerField[_I]): blank: bool = ..., null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_DT, Callable[[], _DT]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_DT, str], Tuple[str, Iterable[Tuple[_DT, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., ) -> None: ... @overload def __init__( - self: BigIntegerField[Optional[int]], - verbose_name: Optional[Union[str, bytes]] = ..., + self: DateTimeField[Optional[datetime]], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -393,30 +1102,107 @@ class BigIntegerField(IntegerField[_I]): blank: bool = ..., null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_DT, Callable[[], _DT]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_DT, str], Tuple[str, Iterable[Tuple[_DT, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + auto_now: bool = ..., + auto_now_add: bool = ..., ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _I: ... # type: ignore [override] - def __set__( - self, instance: Any, value: Union[str, float, int, Combinable, _I] - ) -> None: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> DateTimeField[datetime]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> DateTimeField[Optional[datetime]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[ + Union[Tuple[_DT, str], Tuple[str, Iterable[Tuple[_DT, str]]]] + ], + **kwargs: Any, + ) -> DateTimeField[_DT]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[ + Union[Tuple[_DT, str], Tuple[str, Iterable[Tuple[_DT, str]]]] + ], + **kwargs: Any, + ) -> DateTimeField[Optional[_DT]]: ... -class PositiveBigIntegerField(IntegerField[_I]): +_U = TypeVar("_U", bound=Optional[uuid.UUID]) + +class UUIDField(Generic[_U], Field[Union[str, _U], _U]): + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: None = ..., + **kwargs: Any, + ) -> UUIDField[uuid.UUID]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> UUIDField[Optional[uuid.UUID]]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[False] = ..., + choices: Iterable[Union[Tuple[_U, str], Tuple[str, Iterable[Tuple[_U, str]]]]], + **kwargs: Any, + ) -> UUIDField[_U]: ... + @overload + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_U, str], Tuple[str, Iterable[Tuple[_U, str]]]]], + **kwargs: Any, + ) -> UUIDField[Optional[_U]]: ... + +class FilePathField(Generic[_C], Field[_C, _C]): + path: Union[str, Callable[..., str]] = ... + match: Optional[str] = ... + recursive: bool = ... + allow_files: bool = ... + allow_folders: bool = ... @overload def __init__( - self: PositiveBigIntegerField[int], - verbose_name: Optional[Union[str, bytes]] = ..., + self: FilePathField[str], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -424,24 +1210,31 @@ class PositiveBigIntegerField(IntegerField[_I]): blank: bool = ..., null: Literal[False] = ..., db_index: bool = ..., - default: Any = ..., + default: Union[_C, Callable[[], _C]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + path: Union[str, Callable[..., str]] = ..., + match: Optional[str] = ..., + recursive: bool = ..., + allow_files: bool = ..., + allow_folders: bool = ..., ) -> None: ... @overload def __init__( - self: PositiveBigIntegerField[Optional[int]], - verbose_name: Optional[Union[str, bytes]] = ..., + self: FilePathField[Optional[str]], + verbose_name: Optional[str] = ..., name: Optional[str] = ..., primary_key: bool = ..., max_length: Optional[int] = ..., @@ -449,1010 +1242,136 @@ class PositiveBigIntegerField(IntegerField[_I]): blank: bool = ..., null: Literal[True] = ..., db_index: bool = ..., - default: Any = ..., + default: Optional[Union[_C, Callable[[], _C]]] = ..., editable: bool = ..., auto_created: bool = ..., serialize: bool = ..., unique_for_date: Optional[str] = ..., unique_for_month: Optional[str] = ..., unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., + choices: Iterable[ + Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]] + ] = ..., help_text: str = ..., db_column: Optional[str] = ..., db_tablespace: Optional[str] = ..., validators: Iterable[_ValidatorCallable] = ..., error_messages: Optional[_ErrorMessagesToOverride] = ..., + path: Union[str, Callable[..., str]] = ..., + match: Optional[str] = ..., + recursive: bool = ..., + allow_files: bool = ..., + allow_folders: bool = ..., ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _I: ... # type: ignore [override] - def __set__( - self, instance: Any, value: Union[str, float, int, Combinable, _I] - ) -> None: ... - -_F = TypeVar("_F", bound=Optional[float]) - -class FloatField(Generic[_F], Field[Union[float, int, str, Combinable], float]): @overload - def __init__( - self: FloatField[float], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: FloatField[Optional[float]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _F: ... # type: ignore [override] - def __set__( - self, instance: Any, value: Union[str, float, int, Combinable, _F] - ) -> None: ... - -_DEC = TypeVar("_DEC", bound=Optional[decimal.Decimal]) - -class DecimalField( - Generic[_DEC], - Field[Union[str, float, decimal.Decimal, Combinable], decimal.Decimal], -): - # attributes - max_digits: int = ... - decimal_places: int = ... - @overload - def __init__( - self: DecimalField[decimal.Decimal], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - max_digits: Optional[int] = ..., - decimal_places: Optional[int] = ..., - primary_key: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: DecimalField[Optional[decimal.Decimal]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - max_digits: Optional[int] = ..., - decimal_places: Optional[int] = ..., - primary_key: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _DEC: ... # type: ignore [override] - def __set__( # type: ignore [override] - self, instance: Any, value: Union[str, float, Combinable, _DEC] - ) -> None: ... - -class AutoField(Field[Union[Combinable, int, str, None], int]): - def __init__( - self, - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: bool = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - -_C = TypeVar("_C", bound="Optional[str]") - -class CharField(Generic[_C], Field[str, str]): - @overload - def __init__( - self: CharField[str], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: CharField[Optional[str]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self: CharField[_C], instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self: CharField[_C], instance: Any, value: _C) -> None: ... # type: ignore [override] - -class SlugField(CharField[_C]): - @overload - def __init__( - self: SlugField[str], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - allow_unicode: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: SlugField[Optional[str]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - allow_unicode: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self: SlugField[_C], instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] - -class EmailField(CharField[_C]): - @overload - def __init__( - self: EmailField[str], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: EmailField[Optional[str]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] - -class URLField(CharField[_C]): - @overload - def __init__( - self: URLField[str], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: URLField[Optional[str]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] - -class TextField(Generic[_C], Field[str, str]): - @overload - def __init__( - self: TextField[str], - *, - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: TextField[Optional[str]], - *, - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self: TextField[_C], instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] - -_B = TypeVar("_B", bound=Optional[bool]) - -class BooleanField(Generic[_B], Field[Union[bool, Combinable], bool]): - @overload - def __init__( - self: BooleanField[bool], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: BooleanField[Optional[bool]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _B: ... # type: ignore [override] - def __set__(self, instance: Any, value: _B) -> None: ... # type: ignore [override] - -class IPAddressField(Generic[_C], Field[Union[str, Combinable], str]): - @overload - def __init__( - self: IPAddressField[str], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: IPAddressField[Optional[str]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] - -class GenericIPAddressField( - Generic[_C], Field[Union[str, int, Callable[..., Any], Combinable], str] -): - - default_error_messages: Any = ... - unpack_ipv4: Any = ... - protocol: Any = ... - @overload - def __init__( - self: GenericIPAddressField[str], - verbose_name: Optional[Any] = ..., - name: Optional[Any] = ..., - protocol: str = ..., - unpack_ipv4: bool = ..., - primary_key: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: GenericIPAddressField[Optional[str]], - verbose_name: Optional[Any] = ..., - name: Optional[Any] = ..., - protocol: str = ..., - unpack_ipv4: bool = ..., - primary_key: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] - -class DateTimeCheckMixin: ... - -_D = TypeVar("_D", bound=Optional[date]) - -class DateField( - Generic[_D], DateTimeCheckMixin, Field[Union[str, date, Combinable], date] -): - @overload - def __init__( - self: DateField[date], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - auto_now: bool = ..., - auto_now_add: bool = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - @overload - def __init__( - self: DateField[Optional[date]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - auto_now: bool = ..., - auto_now_add: bool = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _D: ... # type: ignore [override] - def __set__(self, instance: Any, value: _D) -> None: ... # type: ignore [override] - -_TM = TypeVar("_TM", bound=Optional[time]) - -class TimeField( - Generic[_TM], - DateTimeCheckMixin, - Field[Union[str, time, datetime, Combinable], time], -): - @overload - def __init__( - self: TimeField[time], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - auto_now: bool = ..., - auto_now_add: bool = ..., - primary_key: bool = ..., - unique: bool = ..., - blank: bool = ..., + def __new__( + cls, + *args: Any, null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... + choices: None = ..., + **kwargs: Any, + ) -> FilePathField[str]: ... @overload - def __init__( - self: TimeField[Optional[time]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - auto_now: bool = ..., - auto_now_add: bool = ..., - primary_key: bool = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _TM: ... # type: ignore [override] - def __set__(self, instance: Any, value: _TM) -> None: ... # type: ignore [override] - -_DT = TypeVar("_DT", bound=Optional[datetime]) - -class DateTimeField( - Generic[_DT], DateTimeCheckMixin, Field[Union[str, datetime], datetime] -): + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> FilePathField[Optional[str]]: ... @overload - def __init__( - self: DateTimeField[datetime], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - auto_now: bool = ..., - auto_now_add: bool = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., + def __new__( + cls, + *args: Any, null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> FilePathField[_C]: ... @overload - def __init__( - self: DateTimeField[Optional[datetime]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - auto_now: bool = ..., - auto_now_add: bool = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _DT: ... # type: ignore [override] - def __set__(self, instance: Any, value: _DT) -> None: ... # type: ignore [override] + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[Union[Tuple[_C, str], Tuple[str, Iterable[Tuple[_C, str]]]]], + **kwargs: Any, + ) -> FilePathField[Optional[_C]]: ... -_U = TypeVar("_U", bound=Optional[uuid.UUID]) +_BIN = TypeVar("_BIN", bound=Optional[bytes]) -class UUIDField(Generic[_U], Field[Union[str, uuid.UUID], uuid.UUID]): +class BinaryField(Generic[_BIN], Field[Union[_BIN, bytearray, memoryview], _BIN]): @overload - def __init__( - self: UUIDField[uuid.UUID], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., + def __new__( + cls, + *args: Any, null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... + choices: None = ..., + **kwargs: Any, + ) -> BinaryField[bytes]: ... @overload - def __init__( - self: UUIDField[Optional[uuid.UUID]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _U: ... # type: ignore [override] - def __set__(self, instance: Any, value: Union[str, _U]) -> None: ... # type: ignore [override] - -class FilePathField(Generic[_C], Field[str, str]): - path: Any = ... - match: Optional[str] = ... - recursive: bool = ... - allow_files: bool = ... - allow_folders: bool = ... + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> BinaryField[Optional[bytes]]: ... @overload - def __init__( - self: FilePathField[str], - path: Union[str, Callable[..., str]] = ..., - match: Optional[str] = ..., - recursive: bool = ..., - allow_files: bool = ..., - allow_folders: bool = ..., - verbose_name: Optional[str] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: int = ..., - unique: bool = ..., - blank: bool = ..., + def __new__( + cls, + *args: Any, null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... + choices: Iterable[ + Union[Tuple[_BIN, str], Tuple[str, Iterable[Tuple[_BIN, str]]]] + ], + **kwargs: Any, + ) -> BinaryField[_BIN]: ... @overload - def __init__( - self: FilePathField[Optional[str]], - path: Union[str, Callable[..., str]] = ..., - match: Optional[str] = ..., - recursive: bool = ..., - allow_files: bool = ..., - allow_folders: bool = ..., - verbose_name: Optional[str] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: int = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _C: ... # type: ignore [override] - def __set__(self, instance: Any, value: _C) -> None: ... # type: ignore [override] + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[ + Union[Tuple[_BIN, str], Tuple[str, Iterable[Tuple[_BIN, str]]]] + ], + **kwargs: Any, + ) -> BinaryField[Optional[_BIN]]: ... -_BIN = TypeVar("_BIN", bound=Optional[bytes]) +_TD = TypeVar("_TD", bound=Optional[timedelta]) -class BinaryField(Generic[_BIN], Field[Union[bytes, bytearray, memoryview], bytes]): +class DurationField(Generic[_TD], Field[_TD, _TD]): @overload - def __init__( - self: BinaryField[bytes], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., + def __new__( + cls, + *args: Any, null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... + choices: None = ..., + **kwargs: Any, + ) -> DurationField[timedelta]: ... @overload - def __init__( - self: BinaryField[Optional[bytes]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _BIN: ... # type: ignore [override] - def __set__(self, instance: Any, value: _BIN) -> None: ... # type: ignore [override] - -_TD = TypeVar("_TD", bound=Optional[timedelta]) - -class DurationField(Generic[_TD], Field[timedelta, timedelta]): + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: None = ..., + **kwargs: Any, + ) -> DurationField[Optional[timedelta]]: ... @overload - def __init__( - self: DurationField[timedelta], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., + def __new__( + cls, + *args: Any, null: Literal[False] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... + choices: Iterable[ + Union[Tuple[_TD, str], Tuple[str, Iterable[Tuple[_TD, str]]]] + ], + **kwargs: Any, + ) -> DurationField[_TD]: ... @overload - def __init__( - self: DurationField[Optional[timedelta]], - verbose_name: Optional[Union[str, bytes]] = ..., - name: Optional[str] = ..., - primary_key: bool = ..., - max_length: Optional[int] = ..., - unique: bool = ..., - blank: bool = ..., - null: Literal[True] = ..., - db_index: bool = ..., - default: Any = ..., - editable: bool = ..., - auto_created: bool = ..., - serialize: bool = ..., - unique_for_date: Optional[str] = ..., - unique_for_month: Optional[str] = ..., - unique_for_year: Optional[str] = ..., - choices: Optional[_FieldChoices] = ..., - help_text: str = ..., - db_column: Optional[str] = ..., - db_tablespace: Optional[str] = ..., - validators: Iterable[_ValidatorCallable] = ..., - error_messages: Optional[_ErrorMessagesToOverride] = ..., - ) -> None: ... - def __get__(self, instance: Any, owner: Any) -> _TD: ... # type: ignore [override] - def __set__(self, instance: Any, value: _TD) -> None: ... # type: ignore [override] - -class BigAutoField(AutoField): ... + def __new__( + cls, + *args: Any, + null: Literal[True], + choices: Iterable[ + Union[Tuple[_TD, str], Tuple[str, Iterable[Tuple[_TD, str]]]] + ], + **kwargs: Any, + ) -> DurationField[Optional[_TD]]: ... diff --git a/s/lint b/s/lint index 261c3f265..abb9ed4c1 100755 --- a/s/lint +++ b/s/lint @@ -2,20 +2,21 @@ set -ex - # format code if [[ $CI ]]; then - ./.venv/bin/black --check tests typings - ./.venv/bin/isort --check-only tests typings + ./.venv/bin/black --check tests typings + ./.venv/bin/isort --check-only tests typings else - ./.venv/bin/black tests typings - ./.venv/bin/isort tests typings + ./.venv/bin/black tests typings + ./.venv/bin/isort tests typings fi # type check code ./.venv/bin/mypy tests typings +# pyright tests ./node_modules/.bin/pyright tests typings +./.venv/bin/pytest tests typings -p no:warnings -v # lint ./.venv/bin/flake8 tests typings diff --git a/tests/pyright/__init__.py b/tests/pyright/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/pyright/base.py b/tests/pyright/base.py new file mode 100644 index 000000000..7378f90a5 --- /dev/null +++ b/tests/pyright/base.py @@ -0,0 +1,46 @@ +# Slighly based on https://github.com/strawberry-graphql/strawberry/blob/main/tests/pyright/utils.py + +import os +import subprocess +import tempfile +from dataclasses import dataclass +from typing import List, cast + +from typing_extensions import Literal + +_cwd = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +_bin = os.path.join(_cwd, "node_modules", ".bin", "pyright") + + +@dataclass +class Result: + type: Literal["error", "info"] + message: str + line: int + column: int + + @classmethod + def from_output_line(cls, output_line: str) -> "Result": + # an output line looks like: filename.py:11:6 - type: Message + file_info, result = output_line.split("-", maxsplit=1) + + line, column = [int(value) for value in file_info.split(":")[1:]] + type_, message = [value.strip() for value in result.split(":", maxsplit=1)] + type_ = cast(Literal["error", "info"], type_) + + return cls(type=type_, message=message, line=line, column=column) + + +def run_pyright(code: str) -> List[Result]: + with tempfile.NamedTemporaryFile("w", suffix=".py") as f: + f.write(code) + f.flush() + result = subprocess.run([_bin, f.name], cwd=_cwd, stdout=subprocess.PIPE) + + output = result.stdout.decode("utf-8") + results: List[Result] = [] + for line in output.splitlines(): + if line.strip().startswith(f"{f.name}:"): + results.append(Result.from_output_line(line)) + + return results diff --git a/tests/pyright/test_fields.py b/tests/pyright/test_fields.py new file mode 100644 index 000000000..041726b93 --- /dev/null +++ b/tests/pyright/test_fields.py @@ -0,0 +1,185 @@ +from .base import Result, run_pyright + + +def test_integer_with_choices() -> None: + results = run_pyright( + """\ +from django.db import models + +class Foo(models.Model): + integer_with_choices = models.IntegerField( + choices=[ + (1, "First Option"), + (2, "Second Option"), + ], + ) + +f = Foo() +reveal_type(f.integer_with_choices) +f.integer_with_choices == 2 +f.integer_with_choices == 3 +f.integer_with_choices = None +f.integer_with_choices = 3 +f.integer_with_choices = 2 +""" + ) + assert results == [ + Result( + type="info", + message='Type of "f.integer_with_choices" is "Literal[1, 2]"', + line=12, + column=13, + ), + Result( + type="error", + message=( + "Condition will always evaluate to False since the types " + '"Literal[1, 2]" and "Literal[3]" have no overlap (reportUnnecessaryComparison)' + ), + line=14, + column=1, + ), + Result( + type="error", + message='Cannot assign member "integer_with_choices" for type "Foo" (reportGeneralTypeIssues)', + line=15, + column=3, + ), + Result( + type="error", + message='Cannot assign member "integer_with_choices" for type "Foo" (reportGeneralTypeIssues)', + line=16, + column=3, + ), + ] + + +def test_integer_with_choices_nullable() -> None: + results = run_pyright( + """\ +from django.db import models + +class Foo(models.Model): + integer_with_choices_nullable = models.IntegerField( + choices=[ + (1, "First Option"), + (2, "Second Option"), + ], + null=True, + ) + +f = Foo() +reveal_type(f.integer_with_choices_nullable) +f.integer_with_choices_nullable == 2 +f.integer_with_choices_nullable == 3 +f.integer_with_choices_nullable = None +f.integer_with_choices_nullable = 3 +f.integer_with_choices_nullable = 2 +""" + ) + assert results == [ + Result( + type="info", + message='Type of "f.integer_with_choices_nullable" is "Literal[1, 2] | None"', + line=13, + column=13, + ), + Result( + type="error", + message=( + 'Cannot assign member "integer_with_choices_nullable" for type ' + '"Foo" (reportGeneralTypeIssues)' + ), + line=17, + column=3, + ), + ] + + +def test_char_with_choices() -> None: + results = run_pyright( + """\ +from django.db import models + +class Foo(models.Model): + char_with_choices = models.CharField( + choices=[ + ("a", "A"), + ("b", "B"), + ], + ) + +f = Foo() +reveal_type(f.char_with_choices) +f.char_with_choices == "c" +f.char_with_choices == "a" +f.char_with_choices = None +f.char_with_choices = "c" +f.char_with_choices = "b" +""" + ) + assert results == [ + Result( + type="info", + message="Type of \"f.char_with_choices\" is \"Literal['a', 'b']\"", + line=12, + column=13, + ), + Result( + type="error", + message="Condition will always evaluate to False since the types \"Literal['a', 'b']\" and \"Literal['c']\" have no overlap (reportUnnecessaryComparison)", + line=13, + column=1, + ), + Result( + type="error", + message='Cannot assign member "char_with_choices" for type "Foo" (reportGeneralTypeIssues)', + line=15, + column=3, + ), + Result( + type="error", + message='Cannot assign member "char_with_choices" for type "Foo" (reportGeneralTypeIssues)', + line=16, + column=3, + ), + ] + + +def test_char_with_choices_nullable() -> None: + results = run_pyright( + """\ +from django.db import models + +class Foo(models.Model): + char_with_choices_nullable = models.CharField( + choices=[ + ("a", "A"), + ("b", "B"), + ], + null=True, + ) + +f = Foo() +reveal_type(f.char_with_choices_nullable) +f.char_with_choices_nullable == "c" +f.char_with_choices_nullable == "a" +f.char_with_choices_nullable = None +f.char_with_choices_nullable = "c" +f.char_with_choices_nullable = "b" +""" + ) + assert results == [ + Result( + type="info", + message="Type of \"f.char_with_choices_nullable\" is \"Literal['a', 'b'] | None\"", + line=13, + column=13, + ), + Result( + type="error", + message='Cannot assign member "char_with_choices_nullable" for type "Foo" (reportGeneralTypeIssues)', + line=17, + column=3, + ), + ] diff --git a/tests/trout/models.py b/tests/trout/models.py index ef288620b..7275541a9 100644 --- a/tests/trout/models.py +++ b/tests/trout/models.py @@ -87,6 +87,19 @@ class Comment(models.Model): char = models.CharField() char_nullable = models.CharField(null=True) + char_with_choices = models.CharField( + choices=[ + ("a", "A"), + ("b", "B"), + ], + ) + char_with_choices_nullable = models.CharField( + choices=[ + ("a", "A"), + ("b", "B"), + ], + null=True, + ) text = models.TextField() text_nullable = models.TextField(null=True) @@ -100,6 +113,19 @@ class Comment(models.Model): integer = models.IntegerField() integer_nullable = models.IntegerField(null=True) + integer_with_choices = models.IntegerField( + choices=[ + (1, "First Option"), + (2, "Second Option"), + ], + ) + integer_with_choices_nullable = models.IntegerField( + choices=[ + (1, "First Option"), + (2, "Second Option"), + ], + null=True, + ) float = models.FloatField() float_nullable = models.FloatField(null=True) @@ -113,8 +139,8 @@ class Comment(models.Model): email = models.EmailField() email_nullable = models.EmailField(null=True) - decimal = models.DecimalField() - decimal_nullable = models.DecimalField(null=True) + decimal = models.DecimalField(max_digits=20, decimal_places=2) + decimal_nullable = models.DecimalField(null=True, max_digits=20, decimal_places=2) bool = models.BooleanField() bool_nullable = models.BooleanField(null=True) @@ -263,7 +289,7 @@ def main() -> None: process_non_nullable(for_sure_c.integer) # Django way to duplicate an instance - comment.id = None + comment.pk = None comment.save() print(comment.id) @@ -323,6 +349,18 @@ def main() -> None: if not comment.integer and not isinstance(comment.integer, int): print() # type: ignore [unreachable] + process_non_nullable(comment.integer_with_choices) + if isinstance(comment.integer_with_choices_nullable, type(None)): + print(comment.integer_with_choices_nullable) + if comment.integer_with_choices_nullable is not None: + print(comment.integer_with_choices_nullable) + if not isinstance(comment.integer_with_choices, int): + print() # type: ignore [unreachable] + if not comment.integer_with_choices and not isinstance( + comment.integer_with_choices, int + ): + print() # type: ignore [unreachable] + process_non_nullable(comment.float) if isinstance(comment.float_nullable, type(None)): print(comment.float_nullable) @@ -515,6 +553,16 @@ def main() -> None: if not comment.ci_char and not isinstance(comment.ci_char, str): print() # type: ignore [unreachable] + process_non_nullable(comment.char_with_choices) + if isinstance(comment.char_with_choices_nullable, type(None)): + print(comment.char_with_choices_nullable) + if comment.char_with_choices_nullable is not None: + print(comment.char_with_choices_nullable) + if not isinstance(comment.char_with_choices, str): + print() # type: ignore [unreachable] + if not comment.char_with_choices and not isinstance(comment.char_with_choices, str): + print() # type: ignore [unreachable] + process_non_nullable(comment.ci_email) if isinstance(comment.ci_email_nullable, type(None)): print(comment.ci_email_nullable) @@ -929,7 +977,8 @@ class Foo(models.Model): null=True, default=None, blank=True, - max_digits=2, + max_digits=4, + decimal_places=2, ) search_field = SearchVectorField(null=True, help_text="foo") @@ -944,7 +993,7 @@ class HandField(models.Field[Any, Any]): def __init__(self, *args: Any, **kwargs: Any) -> None: kwargs["max_length"] = 104 - super().__init__(*args, **kwargs) # type: ignore [call-arg] + super().__init__(*args, **kwargs) AuthUser.objects.create_superuser(username="foo", email=None, password=None)