Skip to content

Commit

Permalink
Add slicing notation to F expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Aug 21, 2024
1 parent afa4048 commit c206bc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion django-stubs/db/models/expressions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class F(_Deconstructible, Combinable):
name: str
allowed_default: ClassVar[bool]
def __init__(self, name: str) -> None: ...
def __getitem__(self, subscript: int | slice) -> Sliced: ...
def resolve_expression(
self,
query: Any | None = None,
Expand All @@ -154,7 +155,10 @@ class F(_Deconstructible, Combinable):
nulls_first: bool | None = ...,
nulls_last: bool | None = ...,
) -> OrderBy: ...
def copy(self) -> F: ...
def copy(self) -> Self: ...

class Sliced(F):
def __init__(self, obj: F, subscript: int | slice) -> None: ...

class ResolvedOuterRef(F):
contains_aggregate: ClassVar[bool]
Expand Down
3 changes: 2 additions & 1 deletion django-stubs/db/models/fields/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from django.core import validators # due to weird mypy.stubtest error
from django.core.checks import CheckMessage
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Model
from django.db.models.expressions import Col, Combinable, Expression
from django.db.models.expressions import Col, Combinable, Expression, Func
from django.db.models.fields.reverse_related import ForeignObjectRel
from django.db.models.query_utils import Q, RegisterLookupMixin
from django.forms import Widget
Expand Down Expand Up @@ -234,6 +234,7 @@ class Field(RegisterLookupMixin, Generic[_ST, _GT]):
def get_attname(self) -> str: ...
def get_attname_column(self) -> tuple[str, str]: ...
def value_to_string(self, obj: Model) -> str: ...
def slice_expression(self, expression: Expression, start: int, end: int | None) -> Func: ...

class IntegerField(Field[_ST, _GT]):
_pyi_private_set_type: float | int | str | Combinable
Expand Down

0 comments on commit c206bc7

Please sign in to comment.