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 Jan 1, 2024
1 parent 55739e4 commit f9589e9
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 @@ -130,6 +130,7 @@ class TemporalSubtraction(CombinedExpression):
class F(_Deconstructible, Combinable):
name: str
def __init__(self, name: str) -> None: ...
def __getitem__(self, subscript: int | slice) -> Sliced: ...
def resolve_expression(
self,
query: Any = ...,
Expand All @@ -152,7 +153,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 @@ -11,7 +11,7 @@ from django.core.checks import CheckMessage
from django.core.exceptions import FieldDoesNotExist as FieldDoesNotExist
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models import Model
from django.db.models.expressions import Col, Combinable
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 @@ -239,6 +239,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 f9589e9

Please sign in to comment.