Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update db.migrations.operations #2349

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions django-stubs/contrib/postgres/operations.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from typing import Literal

from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations import AddConstraint, AddIndex, RemoveIndex
from django.db.migrations.operations.base import Operation

class CreateExtension(Operation):
reversible: bool
name: str
def __init__(self, name: str) -> None: ...
def extension_exists(self, schema_editor: BaseDatabaseSchemaEditor, extension: str) -> bool: ...
Expand Down Expand Up @@ -37,11 +34,8 @@ class UnaccentExtension(CreateExtension):
class NotInTransactionMixin:
def _ensure_not_in_transaction(self, schema_editor: BaseDatabaseSchemaEditor) -> None: ...

class AddIndexConcurrently(NotInTransactionMixin, AddIndex):
atomic: Literal[False]

class RemoveIndexConcurrently(NotInTransactionMixin, RemoveIndex):
atomic: Literal[False]
class AddIndexConcurrently(NotInTransactionMixin, AddIndex): ...
class RemoveIndexConcurrently(NotInTransactionMixin, RemoveIndex): ...

class CollationOperation(Operation):
name: str
Expand Down
27 changes: 19 additions & 8 deletions django-stubs/db/migrations/operations/base.pyi
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
from collections.abc import Sequence
from typing import Any
from enum import Enum
from typing import Any, ClassVar

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import ProjectState
from django.db.models import Model
from typing_extensions import Self

class OperationCategory(str, Enum):
ADDITION = "+"
REMOVAL = "-"
ALTERATION = "~"
PYTHON = "p"
SQL = "s"
MIXED = "?"
Comment on lines +11 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the actual values seems to be recommended.


class Operation:
reversible: bool
reduces_to_sql: bool
atomic: bool
elidable: bool
serialization_expand_args: list[str]
reversible: ClassVar[bool]
reduces_to_sql: ClassVar[bool]
atomic: ClassVar[bool]
elidable: ClassVar[bool]
serialization_expand_args: ClassVar[list[str]]
category: ClassVar[OperationCategory | None]
Comment on lines +20 to +25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they are all class vars?

_constructor_args: tuple[Sequence[Any], dict[str, Any]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this protected member here? Is it still useful?

def __new__(cls, *args: Any, **kwargs: Any) -> Self: ...
def deconstruct(self) -> tuple[str, Sequence[Any], dict[str, Any]]: ...
Expand All @@ -24,9 +34,10 @@ class Operation:
self, app_label: str, schema_editor: BaseDatabaseSchemaEditor, from_state: ProjectState, to_state: ProjectState
) -> None: ...
def describe(self) -> str: ...
def formatted_description(self) -> str: ...
@property
def migration_name_fragment(self) -> str: ...
def references_model(self, name: str, app_label: str) -> bool: ...
def references_field(self, model_name: str, name: str, app_label: str) -> bool: ...
def allow_migrate_model(self, connection_alias: BaseDatabaseWrapper | str, model: type[Model]) -> bool: ...
def reduce(self, operation: Operation, app_label: str) -> bool | list[Operation]: ...
@property
def migration_name_fragment(self) -> str: ...
3 changes: 3 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,6 @@ django.db.migrations.recorder.Migration@AnnotatedWith
django.contrib.auth.backends.UserModel
django.contrib.auth.forms.UserModel
django.contrib.auth.views.UserModel

# Limited stubtest support for enums (https://github.com/python/mypy/issues/16806)
django.db.migrations.operations.base.OperationCategory.__new__
56 changes: 0 additions & 56 deletions scripts/stubtest/allowlist_todo_django51.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ django.contrib.postgres.fields.array.ArrayField.slice_expression
django.contrib.postgres.fields.citext.CIText
django.contrib.postgres.indexes.BTreeIndex.__init__
django.contrib.postgres.indexes.OpClass.constraint_validation_compatible
django.contrib.postgres.operations.AddConstraintNotValid.category
django.contrib.postgres.operations.AddIndexConcurrently.category
django.contrib.postgres.operations.CreateCollation.category
django.contrib.postgres.operations.CreateExtension.category
django.contrib.postgres.operations.RemoveCollation.category
django.contrib.postgres.operations.RemoveIndexConcurrently.category
django.contrib.postgres.operations.ValidateConstraint.category
django.contrib.sessions.backends.base.SessionBase.aclear_expired
django.contrib.sessions.backends.base.SessionBase.acreate
django.contrib.sessions.backends.base.SessionBase.acycle_key
Expand Down Expand Up @@ -201,57 +194,8 @@ django.db.backends.postgresql.features.DatabaseFeatures.supports_frame_exclusion
django.db.backends.sqlite3.base.DatabaseWrapper.transaction_modes
django.db.backends.sqlite3.features.DatabaseFeatures.supports_frame_exclusion
django.db.backends.sqlite3.operations.DatabaseOperations.force_group_by
django.db.migrations.AddConstraint.category
django.db.migrations.AddField.category
django.db.migrations.AddIndex.category
django.db.migrations.AlterField.category
django.db.migrations.CreateModel.category
django.db.migrations.DeleteModel.category
django.db.migrations.RemoveConstraint.category
django.db.migrations.RemoveField.category
django.db.migrations.RemoveIndex.category
django.db.migrations.RenameField.category
django.db.migrations.RenameIndex.category
django.db.migrations.RenameModel.category
django.db.migrations.RunPython.category
django.db.migrations.RunSQL.category
django.db.migrations.SeparateDatabaseAndState.category
django.db.migrations.autodetector.MigrationAutodetector.generate_altered_index_together
django.db.migrations.autodetector.OperationDependency
django.db.migrations.operations.AddConstraint.category
django.db.migrations.operations.AddField.category
django.db.migrations.operations.AddIndex.category
django.db.migrations.operations.AlterField.category
django.db.migrations.operations.CreateModel.category
django.db.migrations.operations.DeleteModel.category
django.db.migrations.operations.RemoveConstraint.category
django.db.migrations.operations.RemoveField.category
django.db.migrations.operations.RemoveIndex.category
django.db.migrations.operations.RenameField.category
django.db.migrations.operations.RenameIndex.category
django.db.migrations.operations.RenameModel.category
django.db.migrations.operations.RunPython.category
django.db.migrations.operations.RunSQL.category
django.db.migrations.operations.SeparateDatabaseAndState.category
django.db.migrations.operations.base.Operation.category
django.db.migrations.operations.base.Operation.formatted_description
django.db.migrations.operations.base.OperationCategory
django.db.migrations.operations.fields.AddField.category
django.db.migrations.operations.fields.AlterField.category
django.db.migrations.operations.fields.RemoveField.category
django.db.migrations.operations.fields.RenameField.category
django.db.migrations.operations.models.AddConstraint.category
django.db.migrations.operations.models.AddIndex.category
django.db.migrations.operations.models.CreateModel.category
django.db.migrations.operations.models.DeleteModel.category
django.db.migrations.operations.models.ModelOptionOperation.category
django.db.migrations.operations.models.RemoveConstraint.category
django.db.migrations.operations.models.RemoveIndex.category
django.db.migrations.operations.models.RenameIndex.category
django.db.migrations.operations.models.RenameModel.category
django.db.migrations.operations.special.RunPython.category
django.db.migrations.operations.special.RunSQL.category
django.db.migrations.operations.special.SeparateDatabaseAndState.category
django.db.migrations.serializer.FUNCTION_TYPES
django.db.models.CharField.slice_expression
django.db.models.CheckConstraint.__init__
Expand Down
Loading