From 5e2e5feef400e72be1b8a29309aa4ca495bb4e19 Mon Sep 17 00:00:00 2001 From: Maxim Kurnikov Date: Tue, 14 Aug 2018 12:41:05 +0300 Subject: [PATCH] migrations stubs improvements --- django-stubs/db/migrations/__init__.pyi | 4 +- .../db/migrations/operations/models.pyi | 277 ++++++++++++------ django-stubs/db/transaction.pyi | 4 +- 3 files changed, 185 insertions(+), 100 deletions(-) diff --git a/django-stubs/db/migrations/__init__.pyi b/django-stubs/db/migrations/__init__.pyi index e994533..bf1bdcd 100644 --- a/django-stubs/db/migrations/__init__.pyi +++ b/django-stubs/db/migrations/__init__.pyi @@ -2,7 +2,5 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from .operations import * -from .migration import Migration, swappable_dependency -from .migration import Migration, swappable_dependency +from .migration import Migration as Migration, swappable_dependency as swappable_dependency from .operations import * diff --git a/django-stubs/db/migrations/operations/models.pyi b/django-stubs/db/migrations/operations/models.pyi index 8e6b372..ff53ec9 100644 --- a/django-stubs/db/migrations/operations/models.pyi +++ b/django-stubs/db/migrations/operations/models.pyi @@ -1,6 +1,5 @@ from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union -from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.postgres.fields.citext import CIText from django.db.backends.sqlite3.schema import DatabaseSchemaEditor from django.db.migrations.operations.base import Operation @@ -9,275 +8,363 @@ from django.db.models.fields import Field from django.db.models.indexes import Index from django.db.models.manager import Manager -from .fields import (AddField, AlterField, FieldOperation, RemoveField, - RenameField) - class ModelOperation(Operation): name: Any = ... + def __init__(self, name: str) -> None: ... + def name_lower(self) -> str: ... + def references_model( - self, name: str, app_label: Optional[str] = ... + self, name: str, app_label: Optional[str] = ... ) -> bool: ... + def reduce( - self, - operation: Operation, - in_between: List[Operation], - app_label: str = ..., + self, + operation: Operation, + in_between: List[Operation], + app_label: str = ..., ) -> bool: ... + class CreateModel(ModelOperation): serialization_expand_args: Any = ... fields: Any = ... options: Any = ... bases: Any = ... managers: Any = ... + def __init__( - self, - name: str, - fields: List[Tuple[str, Union[CIText, Field]]], - options: Optional[ - Union[ - Dict[str, Union[Set[Tuple[str, str]], Tuple[str], str]], - Dict[str, Union[bool, str]], - ] - ] = ..., - bases: Optional[Tuple[Type[AbstractBaseUser]]] = ..., - managers: Optional[List[Tuple[str, Manager]]] = ..., + self, + name: str, + fields: List[Tuple[str, Union[CIText, Field]]], + options: Optional[Dict[str, Any]] = ..., + bases: Optional[ + Union[Tuple[Type[Any], ...], + Tuple[str, ...]]] = ..., + managers: Optional[List[Tuple[str, Manager]]] = ..., ) -> None: ... + def deconstruct( - self + self ) -> Tuple[ str, List[Any], Dict[str, Union[Dict[str, str], List[Tuple[str, Field]], str]], ]: ... + def state_forwards(self, app_label: str, state: ProjectState) -> None: ... + def database_forwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def database_backwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def describe(self) -> str: ... + def references_model(self, name: str, app_label: str = ...) -> bool: ... + def model_to_key(self, model: str) -> List[str]: ... + def reduce( - self, - operation: Operation, - in_between: List[Operation], - app_label: str = ..., + self, + operation: Operation, + in_between: List[Operation], + app_label: str = ..., ) -> Union[List[CreateModel], bool]: ... + class DeleteModel(ModelOperation): def deconstruct(self) -> Tuple[str, List[Any], Dict[str, str]]: ... + def state_forwards(self, app_label: str, state: ProjectState) -> None: ... + def database_forwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def database_backwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def describe(self) -> str: ... + class RenameModel(ModelOperation): old_name: Any = ... new_name: Any = ... + def __init__(self, old_name: str, new_name: str) -> None: ... + def old_name_lower(self) -> str: ... + def new_name_lower(self) -> str: ... + def deconstruct(self): ... + def state_forwards(self, app_label: str, state: ProjectState) -> None: ... + def database_forwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def database_backwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def references_model(self, name: Any, app_label: Optional[Any] = ...): ... + def describe(self): ... + def reduce( - self, - operation: AlterModelTable, - in_between: List[Any], - app_label: str = ..., + self, + operation: AlterModelTable, + in_between: List[Any], + app_label: str = ..., ) -> bool: ... + class AlterModelTable(ModelOperation): table: Any = ... + def __init__(self, name: str, table: Optional[str]) -> None: ... + def deconstruct(self): ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ): ... + def describe(self): ... + def reduce( - self, operation: Any, in_between: Any, app_label: Optional[Any] = ... + self, operation: Any, in_between: Any, app_label: Optional[Any] = ... ): ... + class ModelOptionOperation(ModelOperation): def reduce( - self, - operation: Operation, - in_between: List[DeleteModel], - app_label: str = ..., + self, + operation: Operation, + in_between: List[DeleteModel], + app_label: str = ..., ) -> bool: ... + class FieldRelatedOptionOperation(ModelOptionOperation): def reduce( - self, operation: Operation, in_between: List[Any], app_label: str = ... + self, operation: Operation, in_between: List[Any], app_label: str = ... ) -> Union[List[Operation], bool]: ... + class AlterUniqueTogether(FieldRelatedOptionOperation): option_name: str = ... unique_together: Any = ... + def __init__( - self, name: str, unique_together: Set[Tuple[str, str]] + self, name: str, unique_together: Set[Tuple[str, ...]] ) -> None: ... + def deconstruct( - self + self ) -> Tuple[str, List[Any], Dict[str, Union[Set[Tuple[str, str]], str]]]: ... + def state_forwards(self, app_label: str, state: ProjectState) -> None: ... + def database_forwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def database_backwards( - self, - app_label: str, - schema_editor: DatabaseSchemaEditor, - from_state: ProjectState, - to_state: ProjectState, + self, + app_label: str, + schema_editor: DatabaseSchemaEditor, + from_state: ProjectState, + to_state: ProjectState, ) -> None: ... + def references_field( - self, model_name: str, name: str, app_label: Optional[str] = ... + self, model_name: str, name: str, app_label: Optional[str] = ... ) -> bool: ... + def describe(self) -> str: ... + class AlterIndexTogether(FieldRelatedOptionOperation): option_name: str = ... index_together: Any = ... + def __init__( - self, name: str, index_together: Set[Tuple[str, str]] + self, name: str, index_together: Set[Tuple[str, str]] ) -> None: ... + def deconstruct(self): ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ): ... + def references_field( - self, model_name: str, name: str, app_label: Optional[str] = ... + self, model_name: str, name: str, app_label: Optional[str] = ... ) -> bool: ... + def describe(self): ... + class AlterOrderWithRespectTo(FieldRelatedOptionOperation): name: str order_with_respect_to: str = ... + def __init__(self, name: str, order_with_respect_to: str) -> None: ... + def deconstruct(self): ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def references_field( - self, model_name: str, name: str, app_label: None = ... + self, model_name: str, name: str, app_label: None = ... ) -> bool: ... + def describe(self): ... + class AlterModelOptions(ModelOptionOperation): ALTER_OPTION_KEYS: Any = ... options: Any = ... + def __init__(self, name: str, options: Dict[str, str]) -> None: ... + def deconstruct(self): ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def describe(self): ... + class AlterModelManagers(ModelOptionOperation): serialization_expand_args: Any = ... managers: Any = ... + def __init__(self, name: Any, managers: Any) -> None: ... + def deconstruct(self): ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def describe(self): ... + class IndexOperation(Operation): option_name: str = ... + def model_name_lower(self): ... + class AddIndex(IndexOperation): model_name: str = ... index: django.db.models.indexes.Index = ... + def __init__(self, model_name: str, index: Index) -> None: ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def deconstruct(self): ... + def describe(self): ... + class RemoveIndex(IndexOperation): model_name: str = ... name: str = ... + def __init__(self, model_name: str, name: str) -> None: ... + def state_forwards(self, app_label: Any, state: Any) -> None: ... + def database_forwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def database_backwards( - self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any + self, app_label: Any, schema_editor: Any, from_state: Any, to_state: Any ) -> None: ... + def deconstruct(self): ... + def describe(self): ... diff --git a/django-stubs/db/transaction.pyi b/django-stubs/db/transaction.pyi index d1acd64..315242e 100644 --- a/django-stubs/db/transaction.pyi +++ b/django-stubs/db/transaction.pyi @@ -1,5 +1,5 @@ from contextlib import ContextDecorator -from typing import Any, Callable, Optional, Union +from typing import Any, Callable, Optional, Union, ContextManager from django.db import ProgrammingError from django.db.backends.sqlite3.base import DatabaseWrapper @@ -31,5 +31,5 @@ class Atomic(ContextDecorator): def atomic( using: Optional[Union[Callable, str]] = ..., savepoint: bool = ... -) -> Callable: ... +) -> ContextManager[Atomic]: ... def non_atomic_requests(using: Callable = ...) -> Callable: ...