mirror of
https://github.com/davidhalter/django-stubs.git
synced 2026-09-17 17:23:17 +08:00
preliminary support for strict_optional
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import uuid
|
||||
from datetime import date, time, datetime, timedelta
|
||||
from typing import Any, Optional, Tuple, Iterable, Callable, Dict, Union, Type, TypeVar, Generic
|
||||
import decimal
|
||||
|
||||
from typing_extensions import Literal
|
||||
import uuid
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from typing import Any, Callable, Dict, Generic, Iterable, Optional, Tuple, Type, TypeVar, Union
|
||||
|
||||
from django.db.models import Model
|
||||
from django.db.models.query_utils import RegisterLookupMixin
|
||||
|
||||
from django.db.models.expressions import F, Combinable
|
||||
from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist
|
||||
from django.forms import Widget, Field as FormField
|
||||
from django.db.models.expressions import Combinable
|
||||
from django.db.models.query_utils import RegisterLookupMixin
|
||||
from django.forms import Field as FormField, Widget
|
||||
from typing_extensions import Literal
|
||||
|
||||
from .mixins import NOT_PROVIDED as NOT_PROVIDED
|
||||
|
||||
_Choice = Tuple[Any, Any]
|
||||
@@ -20,7 +19,15 @@ _FieldChoices = Iterable[Union[_Choice, _ChoiceNamedGroup]]
|
||||
_ValidatorCallable = Callable[..., None]
|
||||
_ErrorMessagesToOverride = Dict[str, Any]
|
||||
|
||||
class Field(RegisterLookupMixin):
|
||||
# __set__ value type
|
||||
_ST = TypeVar("_ST")
|
||||
# __get__ return type
|
||||
_GT = TypeVar("_GT")
|
||||
|
||||
class Field(RegisterLookupMixin, Generic[_ST, _GT]):
|
||||
_pyi_private_set_type: Any
|
||||
_pyi_private_get_type: Any
|
||||
|
||||
widget: Widget
|
||||
help_text: str
|
||||
db_table: str
|
||||
@@ -52,7 +59,8 @@ class Field(RegisterLookupMixin):
|
||||
validators: Iterable[_ValidatorCallable] = ...,
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
def __get__(self, instance, owner) -> Any: ...
|
||||
def __set__(self, instance, value: _ST) -> None: ...
|
||||
def __get__(self, instance, owner) -> _GT: ...
|
||||
def deconstruct(self) -> Any: ...
|
||||
def set_attributes_from_name(self, name: str) -> None: ...
|
||||
def db_type(self, connection: Any) -> str: ...
|
||||
@@ -63,23 +71,25 @@ class Field(RegisterLookupMixin):
|
||||
def contribute_to_class(self, cls: Type[Model], name: str, private_only: bool = ...) -> None: ...
|
||||
def to_python(self, value: Any) -> Any: ...
|
||||
|
||||
class IntegerField(Field):
|
||||
def __set__(self, instance, value: Union[int, Combinable, Literal[""]]) -> None: ...
|
||||
def __get__(self, instance, owner) -> int: ...
|
||||
class IntegerField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[int, Combinable, Literal[""]]
|
||||
_pyi_private_get_type: int
|
||||
|
||||
class PositiveIntegerRelDbTypeMixin:
|
||||
def rel_db_type(self, connection: Any): ...
|
||||
|
||||
class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField): ...
|
||||
class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField): ...
|
||||
class SmallIntegerField(IntegerField): ...
|
||||
class BigIntegerField(IntegerField): ...
|
||||
class PositiveIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_ST, _GT]): ...
|
||||
class PositiveSmallIntegerField(PositiveIntegerRelDbTypeMixin, IntegerField[_ST, _GT]): ...
|
||||
class SmallIntegerField(IntegerField[_ST, _GT]): ...
|
||||
class BigIntegerField(IntegerField[_ST, _GT]): ...
|
||||
|
||||
class FloatField(Field):
|
||||
def __set__(self, instance, value: Union[float, int, str, Combinable]) -> float: ...
|
||||
def __get__(self, instance, owner) -> float: ...
|
||||
class FloatField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[float, int, str, Combinable]
|
||||
_pyi_private_get_type: float
|
||||
|
||||
class DecimalField(Field):
|
||||
class DecimalField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, float, decimal.Decimal, Combinable]
|
||||
_pyi_private_get_type: decimal.Decimal
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -102,13 +112,14 @@ class DecimalField(Field):
|
||||
validators: Iterable[_ValidatorCallable] = ...,
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
def __set__(self, instance, value: Union[str, float, decimal.Decimal, Combinable]) -> decimal.Decimal: ...
|
||||
def __get__(self, instance, owner) -> decimal.Decimal: ...
|
||||
|
||||
class AutoField(Field):
|
||||
def __get__(self, instance, owner) -> int: ...
|
||||
class AutoField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[Combinable, int, str]
|
||||
_pyi_private_get_type: int
|
||||
|
||||
class CharField(Field):
|
||||
class CharField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, int, Combinable]
|
||||
_pyi_private_get_type: str
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -133,10 +144,8 @@ class CharField(Field):
|
||||
validators: Iterable[_ValidatorCallable] = ...,
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
def __set__(self, instance, value: Union[str, int, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> str: ...
|
||||
|
||||
class SlugField(CharField):
|
||||
class SlugField(CharField[_ST, _GT]):
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -163,25 +172,29 @@ class SlugField(CharField):
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
|
||||
class EmailField(CharField): ...
|
||||
class URLField(CharField): ...
|
||||
class EmailField(CharField[_ST, _GT]): ...
|
||||
class URLField(CharField[_ST, _GT]): ...
|
||||
|
||||
class TextField(Field):
|
||||
def __set__(self, instance, value: Union[str, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> str: ...
|
||||
class TextField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, Combinable]
|
||||
_pyi_private_get_type: str
|
||||
|
||||
class BooleanField(Field):
|
||||
def __set__(self, instance, value: Union[bool, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> bool: ...
|
||||
class BooleanField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[bool, Combinable]
|
||||
_pyi_private_get_type: bool
|
||||
|
||||
class NullBooleanField(Field):
|
||||
def __set__(self, instance, value: Optional[Union[bool, Combinable]]) -> None: ...
|
||||
def __get__(self, instance, owner) -> Optional[bool]: ...
|
||||
class NullBooleanField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Optional[Union[bool, Combinable]]
|
||||
_pyi_private_get_type: Optional[bool]
|
||||
|
||||
class IPAddressField(Field):
|
||||
def __get__(self, instance, owner) -> str: ...
|
||||
class IPAddressField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, Combinable]
|
||||
_pyi_private_get_type: str
|
||||
|
||||
class GenericIPAddressField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, int, Callable[..., Any], Combinable]
|
||||
_pyi_private_get_type: str
|
||||
|
||||
class GenericIPAddressField(Field):
|
||||
default_error_messages: Any = ...
|
||||
unpack_ipv4: Any = ...
|
||||
protocol: Any = ...
|
||||
@@ -207,12 +220,12 @@ class GenericIPAddressField(Field):
|
||||
validators: Iterable[_ValidatorCallable] = ...,
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
) -> None: ...
|
||||
def __set__(self, instance, value: Union[str, int, Callable[..., Any], Combinable]): ...
|
||||
def __get__(self, instance, owner) -> str: ...
|
||||
|
||||
class DateTimeCheckMixin: ...
|
||||
|
||||
class DateField(DateTimeCheckMixin, Field):
|
||||
class DateField(DateTimeCheckMixin, Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, date, datetime, Combinable]
|
||||
_pyi_private_get_type: date
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -236,10 +249,10 @@ class DateField(DateTimeCheckMixin, Field):
|
||||
validators: Iterable[_ValidatorCallable] = ...,
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
def __set__(self, instance, value: Union[str, date, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> date: ...
|
||||
|
||||
class TimeField(DateTimeCheckMixin, Field):
|
||||
class TimeField(DateTimeCheckMixin, Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, time, datetime, Combinable]
|
||||
_pyi_private_get_type: time
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -262,18 +275,15 @@ class TimeField(DateTimeCheckMixin, Field):
|
||||
validators: Iterable[_ValidatorCallable] = ...,
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
def __set__(self, instance, value: Union[str, time, datetime, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> time: ...
|
||||
|
||||
class DateTimeField(DateField):
|
||||
def __set__(self, instance, value: Union[str, date, datetime, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> datetime: ...
|
||||
class DateTimeField(DateField[_ST, _GT]):
|
||||
_pyi_private_get_type: datetime
|
||||
|
||||
class UUIDField(Field):
|
||||
def __set__(self, instance, value: Union[str, uuid.UUID]) -> None: ...
|
||||
def __get__(self, instance, owner) -> uuid.UUID: ...
|
||||
class UUIDField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, uuid.UUID]
|
||||
_pyi_private_get_type: uuid.UUID
|
||||
|
||||
class FilePathField(Field):
|
||||
class FilePathField(Field[_ST, _GT]):
|
||||
path: str = ...
|
||||
match: Optional[Any] = ...
|
||||
recursive: bool = ...
|
||||
@@ -306,10 +316,10 @@ class FilePathField(Field):
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
|
||||
class BinaryField(Field): ...
|
||||
class BinaryField(Field[_ST, _GT]): ...
|
||||
|
||||
class DurationField(Field):
|
||||
def __get__(self, instance, owner) -> timedelta: ...
|
||||
class DurationField(Field[_ST, _GT]):
|
||||
_pyi_private_get_type: timedelta
|
||||
|
||||
class BigAutoField(AutoField): ...
|
||||
class CommaSeparatedIntegerField(CharField): ...
|
||||
class BigAutoField(AutoField[_ST, _GT]): ...
|
||||
class CommaSeparatedIntegerField(CharField[_ST, _GT]): ...
|
||||
|
||||
@@ -49,7 +49,12 @@ _ErrorMessagesToOverride = Dict[str, Any]
|
||||
|
||||
RECURSIVE_RELATIONSHIP_CONSTANT: str = ...
|
||||
|
||||
class RelatedField(FieldCacheMixin, Field):
|
||||
# __set__ value type
|
||||
_ST = TypeVar("_ST")
|
||||
# __get__ return type
|
||||
_GT = TypeVar("_GT")
|
||||
|
||||
class RelatedField(FieldCacheMixin, Field[_ST, _GT]):
|
||||
one_to_many: bool = ...
|
||||
one_to_one: bool = ...
|
||||
many_to_many: bool = ...
|
||||
@@ -83,6 +88,7 @@ class ForeignObject(RelatedField):
|
||||
related_query_name: None = ...,
|
||||
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any]]] = ...,
|
||||
parent_link: bool = ...,
|
||||
db_constraint: bool = ...,
|
||||
swappable: bool = ...,
|
||||
verbose_name: Optional[str] = ...,
|
||||
name: Optional[str] = ...,
|
||||
@@ -103,17 +109,82 @@ class ForeignObject(RelatedField):
|
||||
error_messages: Optional[_ErrorMessagesToOverride] = ...,
|
||||
): ...
|
||||
|
||||
class ForeignKey(RelatedField, Generic[_T]):
|
||||
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
||||
def __set__(self, instance, value: Union[Model, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> _T: ...
|
||||
class ForeignKey(RelatedField[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[Any, Combinable]
|
||||
_pyi_private_get_type: Any
|
||||
def __init__(
|
||||
self,
|
||||
to: Union[Type[Model], str],
|
||||
on_delete: Callable[..., None],
|
||||
to_field: Optional[str] = ...,
|
||||
related_name: str = ...,
|
||||
related_query_name: Optional[str] = ...,
|
||||
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any], Q]] = ...,
|
||||
parent_link: bool = ...,
|
||||
db_constraint: bool = ...,
|
||||
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] = ...,
|
||||
): ...
|
||||
|
||||
class OneToOneField(RelatedField, Generic[_T]):
|
||||
def __init__(self, to: Union[Type[_T], str], on_delete: Any, related_name: str = ..., **kwargs): ...
|
||||
def __set__(self, instance, value: Union[Model, Combinable]) -> None: ...
|
||||
def __get__(self, instance, owner) -> _T: ...
|
||||
class OneToOneField(RelatedField[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[Any, Combinable]
|
||||
_pyi_private_get_type: Any
|
||||
def __init__(
|
||||
self,
|
||||
to: Union[Type[Model], str],
|
||||
on_delete: Any,
|
||||
to_field: Optional[str] = ...,
|
||||
related_name: str = ...,
|
||||
related_query_name: Optional[str] = ...,
|
||||
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any], Q]] = ...,
|
||||
parent_link: bool = ...,
|
||||
db_constraint: bool = ...,
|
||||
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] = ...,
|
||||
): ...
|
||||
|
||||
class ManyToManyField(RelatedField[_ST, _GT]):
|
||||
_pyi_private_set_type: Sequence[Any]
|
||||
_pyi_private_get_type: RelatedManager[Any]
|
||||
|
||||
class ManyToManyField(RelatedField, Generic[_T]):
|
||||
many_to_many: bool = ...
|
||||
many_to_one: bool = ...
|
||||
one_to_many: bool = ...
|
||||
@@ -127,17 +198,35 @@ class ManyToManyField(RelatedField, Generic[_T]):
|
||||
to: Union[Type[_T], str],
|
||||
related_name: Optional[str] = ...,
|
||||
related_query_name: Optional[str] = ...,
|
||||
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any]]] = ...,
|
||||
limit_choices_to: Optional[Union[Dict[str, Any], Callable[[], Any], Q]] = ...,
|
||||
symmetrical: Optional[bool] = ...,
|
||||
through: Optional[Union[str, Type[Model]]] = ...,
|
||||
through_fields: Optional[Tuple[str, str]] = ...,
|
||||
db_constraint: bool = ...,
|
||||
db_table: Optional[str] = ...,
|
||||
swappable: bool = ...,
|
||||
**kwargs: Any
|
||||
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: ...
|
||||
def __set__(self, instance, value: Sequence[_T]) -> None: ...
|
||||
def __get__(self, instance, owner) -> RelatedManager[_T]: ...
|
||||
def check(self, **kwargs: Any) -> List[Any]: ...
|
||||
def deconstruct(self) -> Tuple[Optional[str], str, List[Any], Dict[str, str]]: ...
|
||||
def get_path_info(self, filtered_relation: None = ...) -> List[PathInfo]: ...
|
||||
|
||||
Reference in New Issue
Block a user