From e8a97e301c22c7d1339dec8ab8cd9ce70929259a Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Tue, 13 Apr 2021 12:18:13 +0200 Subject: [PATCH] [3.2] Adjust model indexes (#587) --- django-stubs/db/models/indexes.pyi | 11 ++++++++--- tests/typecheck/models/test_indexes.yml | 10 ++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/typecheck/models/test_indexes.yml diff --git a/django-stubs/db/models/indexes.pyi b/django-stubs/db/models/indexes.pyi index cb33b49..183f5b5 100644 --- a/django-stubs/db/models/indexes.pyi +++ b/django-stubs/db/models/indexes.pyi @@ -1,10 +1,12 @@ -from typing import Any, List, Optional, Sequence, Tuple, Type +from typing import Any, List, Optional, Sequence, Tuple, Type, Union from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.ddl_references import Statement from django.db.models.base import Model +from django.db.models.expressions import BaseExpression, Combinable from django.db.models.query_utils import Q + class Index: model: Type[Model] suffix: str = ... @@ -15,14 +17,17 @@ class Index: db_tablespace: Optional[str] = ... opclasses: Sequence[str] = ... condition: Optional[Q] = ... + expressions: Sequence[Union[Union[BaseExpression, Combinable]]] + include: Sequence[str] def __init__( self, - *, + *expressions: Union[BaseExpression, Combinable, str], fields: Sequence[str] = ..., name: Optional[str] = ..., db_tablespace: Optional[str] = ..., opclasses: Sequence[str] = ..., - condition: Optional[Q] = ... + condition: Optional[Q] = ..., + include: Optional[Sequence[str]] = ..., ) -> None: ... def check_name(self) -> List[str]: ... def create_sql( diff --git a/tests/typecheck/models/test_indexes.yml b/tests/typecheck/models/test_indexes.yml new file mode 100644 index 0000000..ad3e82b --- /dev/null +++ b/tests/typecheck/models/test_indexes.yml @@ -0,0 +1,10 @@ +- case: model_index + main: | + from django.db import models + from django.db.models.functions import Lower + models.Index(fields=["foo"]) + models.Index("foo", models.F("bar"), Lower("baz"), name="test") + models.Index("foo", name="test", opclasses=["bar"]) + models.Index("foo", name="test", condition=models.Q(foo=1)) + models.Index("foo", name="test", include=["bar"]) +