mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
add support for typechecking of filter/get/exclude arguments (#183)
* add support for typechecking of filter/get/exclude arguments * linting
This commit is contained in:
@@ -43,6 +43,7 @@ _GT = TypeVar("_GT")
|
||||
class Field(RegisterLookupMixin, Generic[_ST, _GT]):
|
||||
_pyi_private_set_type: Any
|
||||
_pyi_private_get_type: Any
|
||||
_pyi_lookup_exact_type: Any
|
||||
|
||||
widget: Widget
|
||||
help_text: str
|
||||
@@ -131,6 +132,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
|
||||
class IntegerField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[float, int, str, Combinable]
|
||||
_pyi_private_get_type: int
|
||||
_pyi_lookup_exact_type: int
|
||||
|
||||
class PositiveIntegerRelDbTypeMixin:
|
||||
def rel_db_type(self, connection: Any): ...
|
||||
@@ -143,10 +145,12 @@ class BigIntegerField(IntegerField[_ST, _GT]): ...
|
||||
class FloatField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[float, int, str, Combinable]
|
||||
_pyi_private_get_type: float
|
||||
_pyi_lookup_exact_type: float
|
||||
|
||||
class DecimalField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, float, decimal.Decimal, Combinable]
|
||||
_pyi_private_get_type: decimal.Decimal
|
||||
_pyi_lookup_exact_type: Union[str, decimal.Decimal]
|
||||
# attributes
|
||||
max_digits: int = ...
|
||||
decimal_places: int = ...
|
||||
@@ -176,10 +180,13 @@ class DecimalField(Field[_ST, _GT]):
|
||||
class AutoField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[Combinable, int, str]
|
||||
_pyi_private_get_type: int
|
||||
_pyi_lookup_exact_type: int
|
||||
|
||||
class CharField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, int, Combinable]
|
||||
_pyi_private_get_type: str
|
||||
# objects are converted to string before comparison
|
||||
_pyi_lookup_exact_type: Any
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -238,14 +245,18 @@ class URLField(CharField[_ST, _GT]): ...
|
||||
class TextField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, Combinable]
|
||||
_pyi_private_get_type: str
|
||||
# objects are converted to string before comparison
|
||||
_pyi_lookup_exact_type: Any
|
||||
|
||||
class BooleanField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[bool, Combinable]
|
||||
_pyi_private_get_type: bool
|
||||
_pyi_lookup_exact_type: bool
|
||||
|
||||
class NullBooleanField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Optional[Union[bool, Combinable]]
|
||||
_pyi_private_get_type: Optional[bool]
|
||||
_pyi_lookup_exact_type: Optional[bool]
|
||||
|
||||
class IPAddressField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, Combinable]
|
||||
@@ -286,6 +297,7 @@ class DateTimeCheckMixin: ...
|
||||
class DateField(DateTimeCheckMixin, Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, date, Combinable]
|
||||
_pyi_private_get_type: date
|
||||
_pyi_lookup_exact_type: Union[str, date]
|
||||
def __init__(
|
||||
self,
|
||||
verbose_name: Optional[Union[str, bytes]] = ...,
|
||||
@@ -338,6 +350,7 @@ class TimeField(DateTimeCheckMixin, Field[_ST, _GT]):
|
||||
|
||||
class DateTimeField(DateField[_ST, _GT]):
|
||||
_pyi_private_get_type: datetime
|
||||
_pyi_lookup_exact_type: Union[str, datetime]
|
||||
|
||||
class UUIDField(Field[_ST, _GT]):
|
||||
_pyi_private_set_type: Union[str, uuid.UUID]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime
|
||||
from typing import Any, Iterable, List, Mapping, Optional, Tuple, Type, Union
|
||||
from typing import Any, Iterable, List, Optional, Tuple, Type, Union, Mapping, TypeVar, Generic
|
||||
|
||||
from django.db.backends.sqlite3.base import DatabaseWrapper
|
||||
from django.db.models.expressions import Expression, Func
|
||||
@@ -10,7 +10,9 @@ from django.utils.safestring import SafeText
|
||||
|
||||
from django.db.models.fields import TextField, related_lookups
|
||||
|
||||
class Lookup:
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class Lookup(Generic[_T]):
|
||||
lookup_name: str = ...
|
||||
prepare_rhs: bool = ...
|
||||
can_use_none_as_rhs: bool = ...
|
||||
@@ -47,7 +49,7 @@ class Transform(RegisterLookupMixin, Func):
|
||||
def lhs(self) -> Expression: ...
|
||||
def get_bilateral_transforms(self) -> List[Type[Transform]]: ...
|
||||
|
||||
class BuiltinLookup(Lookup):
|
||||
class BuiltinLookup(Lookup[_T]):
|
||||
def get_rhs_op(self, connection: DatabaseWrapper, rhs: str) -> str: ...
|
||||
|
||||
class FieldGetDbPrepValueMixin:
|
||||
@@ -62,21 +64,21 @@ class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin):
|
||||
class Exact(FieldGetDbPrepValueMixin, BuiltinLookup): ...
|
||||
class IExact(BuiltinLookup): ...
|
||||
class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup): ...
|
||||
class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): ...
|
||||
class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup): ...
|
||||
class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ...
|
||||
class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup[_T]): ...
|
||||
class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup): ...
|
||||
|
||||
class IntegerFieldFloatRounding:
|
||||
rhs: Any = ...
|
||||
def get_prep_lookup(self) -> Any: ...
|
||||
|
||||
class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual): ...
|
||||
class IntegerLessThan(IntegerFieldFloatRounding, LessThan): ...
|
||||
class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual[Union[int, float]]): ...
|
||||
class IntegerLessThan(IntegerFieldFloatRounding, LessThan[Union[int, float]]): ...
|
||||
|
||||
class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
|
||||
def split_parameter_list_as_sql(self, compiler: Any, connection: Any): ...
|
||||
|
||||
class PatternLookup(BuiltinLookup):
|
||||
class PatternLookup(BuiltinLookup[str]):
|
||||
param_pattern: str = ...
|
||||
|
||||
class Contains(PatternLookup): ...
|
||||
@@ -86,8 +88,8 @@ class IStartsWith(StartsWith): ...
|
||||
class EndsWith(PatternLookup): ...
|
||||
class IEndsWith(EndsWith): ...
|
||||
class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup): ...
|
||||
class IsNull(BuiltinLookup): ...
|
||||
class Regex(BuiltinLookup): ...
|
||||
class IsNull(BuiltinLookup[bool]): ...
|
||||
class Regex(BuiltinLookup[str]): ...
|
||||
class IRegex(Regex): ...
|
||||
|
||||
class YearLookup(Lookup):
|
||||
|
||||
Reference in New Issue
Block a user