alembic 1.13.0__py3-none-any.whl → 1.13.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. alembic/__init__.py +1 -1
  2. alembic/autogenerate/__init__.py +10 -10
  3. alembic/autogenerate/api.py +9 -7
  4. alembic/autogenerate/compare.py +6 -5
  5. alembic/autogenerate/render.py +34 -24
  6. alembic/autogenerate/rewriter.py +26 -13
  7. alembic/command.py +27 -16
  8. alembic/config.py +25 -19
  9. alembic/context.pyi +10 -5
  10. alembic/ddl/__init__.py +1 -1
  11. alembic/ddl/_autogen.py +19 -13
  12. alembic/ddl/base.py +17 -13
  13. alembic/ddl/impl.py +27 -19
  14. alembic/ddl/mssql.py +4 -1
  15. alembic/ddl/mysql.py +54 -34
  16. alembic/ddl/oracle.py +9 -4
  17. alembic/ddl/postgresql.py +18 -10
  18. alembic/ddl/sqlite.py +8 -6
  19. alembic/op.pyi +46 -8
  20. alembic/operations/base.py +69 -16
  21. alembic/operations/batch.py +7 -8
  22. alembic/operations/ops.py +57 -35
  23. alembic/operations/schemaobj.py +11 -8
  24. alembic/operations/toimpl.py +3 -0
  25. alembic/runtime/environment.py +20 -13
  26. alembic/runtime/migration.py +34 -18
  27. alembic/script/base.py +24 -24
  28. alembic/script/revision.py +53 -33
  29. alembic/script/write_hooks.py +3 -0
  30. alembic/templates/async/alembic.ini.mako +3 -3
  31. alembic/templates/generic/alembic.ini.mako +2 -2
  32. alembic/templates/multidb/alembic.ini.mako +2 -2
  33. alembic/testing/fixtures.py +20 -8
  34. alembic/testing/suite/test_autogen_computed.py +1 -0
  35. alembic/testing/suite/test_environment.py +3 -3
  36. alembic/util/__init__.py +31 -31
  37. alembic/util/compat.py +25 -8
  38. alembic/util/langhelpers.py +78 -36
  39. alembic/util/messaging.py +15 -6
  40. alembic/util/pyfiles.py +7 -3
  41. alembic/util/sqla_compat.py +41 -14
  42. {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/LICENSE +2 -2
  43. {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/METADATA +1 -1
  44. alembic-1.13.2.dist-info/RECORD +83 -0
  45. {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/WHEEL +1 -1
  46. alembic-1.13.0.dist-info/RECORD +0 -83
  47. {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/entry_points.txt +0 -0
  48. {alembic-1.13.0.dist-info → alembic-1.13.2.dist-info}/top_level.txt +0 -0
alembic/op.pyi CHANGED
@@ -12,6 +12,7 @@ from typing import List
12
12
  from typing import Literal
13
13
  from typing import Mapping
14
14
  from typing import Optional
15
+ from typing import overload
15
16
  from typing import Sequence
16
17
  from typing import Tuple
17
18
  from typing import Type
@@ -35,12 +36,28 @@ if TYPE_CHECKING:
35
36
  from sqlalchemy.sql.type_api import TypeEngine
36
37
  from sqlalchemy.util import immutabledict
37
38
 
38
- from .operations.ops import BatchOperations
39
+ from .operations.base import BatchOperations
40
+ from .operations.ops import AddColumnOp
41
+ from .operations.ops import AddConstraintOp
42
+ from .operations.ops import AlterColumnOp
43
+ from .operations.ops import AlterTableOp
44
+ from .operations.ops import BulkInsertOp
45
+ from .operations.ops import CreateIndexOp
46
+ from .operations.ops import CreateTableCommentOp
47
+ from .operations.ops import CreateTableOp
48
+ from .operations.ops import DropColumnOp
49
+ from .operations.ops import DropConstraintOp
50
+ from .operations.ops import DropIndexOp
51
+ from .operations.ops import DropTableCommentOp
52
+ from .operations.ops import DropTableOp
53
+ from .operations.ops import ExecuteSQLOp
39
54
  from .operations.ops import MigrateOperation
40
55
  from .runtime.migration import MigrationContext
41
56
  from .util.sqla_compat import _literal_bindparam
42
57
 
43
58
  _T = TypeVar("_T")
59
+ _C = TypeVar("_C", bound=Callable[..., Any])
60
+
44
61
  ### end imports ###
45
62
 
46
63
  def add_column(
@@ -132,8 +149,8 @@ def alter_column(
132
149
  comment: Union[str, Literal[False], None] = False,
133
150
  server_default: Any = False,
134
151
  new_column_name: Optional[str] = None,
135
- type_: Union[TypeEngine, Type[TypeEngine], None] = None,
136
- existing_type: Union[TypeEngine, Type[TypeEngine], None] = None,
152
+ type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
153
+ existing_type: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
137
154
  existing_server_default: Union[
138
155
  str, bool, Identity, Computed, None
139
156
  ] = False,
@@ -230,7 +247,7 @@ def batch_alter_table(
230
247
  table_name: str,
231
248
  schema: Optional[str] = None,
232
249
  recreate: Literal["auto", "always", "never"] = "auto",
233
- partial_reordering: Optional[tuple] = None,
250
+ partial_reordering: Optional[Tuple[Any, ...]] = None,
234
251
  copy_from: Optional[Table] = None,
235
252
  table_args: Tuple[Any, ...] = (),
236
253
  table_kwargs: Mapping[str, Any] = immutabledict({}),
@@ -377,7 +394,7 @@ def batch_alter_table(
377
394
 
378
395
  def bulk_insert(
379
396
  table: Union[Table, TableClause],
380
- rows: List[dict],
397
+ rows: List[Dict[str, Any]],
381
398
  *,
382
399
  multiinsert: bool = True,
383
400
  ) -> None:
@@ -1162,7 +1179,7 @@ def get_context() -> MigrationContext:
1162
1179
 
1163
1180
  """
1164
1181
 
1165
- def implementation_for(op_cls: Any) -> Callable[..., Any]:
1182
+ def implementation_for(op_cls: Any) -> Callable[[_C], _C]:
1166
1183
  """Register an implementation for a given :class:`.MigrateOperation`.
1167
1184
 
1168
1185
  This is part of the operation extensibility API.
@@ -1174,7 +1191,7 @@ def implementation_for(op_cls: Any) -> Callable[..., Any]:
1174
1191
  """
1175
1192
 
1176
1193
  def inline_literal(
1177
- value: Union[str, int], type_: Optional[TypeEngine] = None
1194
+ value: Union[str, int], type_: Optional[TypeEngine[Any]] = None
1178
1195
  ) -> _literal_bindparam:
1179
1196
  r"""Produce an 'inline literal' expression, suitable for
1180
1197
  using in an INSERT, UPDATE, or DELETE statement.
@@ -1218,6 +1235,27 @@ def inline_literal(
1218
1235
 
1219
1236
  """
1220
1237
 
1238
+ @overload
1239
+ def invoke(operation: CreateTableOp) -> Table: ...
1240
+ @overload
1241
+ def invoke(
1242
+ operation: Union[
1243
+ AddConstraintOp,
1244
+ DropConstraintOp,
1245
+ CreateIndexOp,
1246
+ DropIndexOp,
1247
+ AddColumnOp,
1248
+ AlterColumnOp,
1249
+ AlterTableOp,
1250
+ CreateTableCommentOp,
1251
+ DropTableCommentOp,
1252
+ DropColumnOp,
1253
+ BulkInsertOp,
1254
+ DropTableOp,
1255
+ ExecuteSQLOp,
1256
+ ]
1257
+ ) -> None: ...
1258
+ @overload
1221
1259
  def invoke(operation: MigrateOperation) -> Any:
1222
1260
  """Given a :class:`.MigrateOperation`, invoke it in terms of
1223
1261
  this :class:`.Operations` instance.
@@ -1226,7 +1264,7 @@ def invoke(operation: MigrateOperation) -> Any:
1226
1264
 
1227
1265
  def register_operation(
1228
1266
  name: str, sourcename: Optional[str] = None
1229
- ) -> Callable[[_T], _T]:
1267
+ ) -> Callable[[Type[_T]], Type[_T]]:
1230
1268
  """Register a new operation for this class.
1231
1269
 
1232
1270
  This method is normally used to add new operations
@@ -1,3 +1,5 @@
1
+ # mypy: allow-untyped-calls
2
+
1
3
  from __future__ import annotations
2
4
 
3
5
  from contextlib import contextmanager
@@ -10,7 +12,9 @@ from typing import Dict
10
12
  from typing import Iterator
11
13
  from typing import List # noqa
12
14
  from typing import Mapping
15
+ from typing import NoReturn
13
16
  from typing import Optional
17
+ from typing import overload
14
18
  from typing import Sequence # noqa
15
19
  from typing import Tuple
16
20
  from typing import Type # noqa
@@ -47,12 +51,28 @@ if TYPE_CHECKING:
47
51
  from sqlalchemy.types import TypeEngine
48
52
 
49
53
  from .batch import BatchOperationsImpl
54
+ from .ops import AddColumnOp
55
+ from .ops import AddConstraintOp
56
+ from .ops import AlterColumnOp
57
+ from .ops import AlterTableOp
58
+ from .ops import BulkInsertOp
59
+ from .ops import CreateIndexOp
60
+ from .ops import CreateTableCommentOp
61
+ from .ops import CreateTableOp
62
+ from .ops import DropColumnOp
63
+ from .ops import DropConstraintOp
64
+ from .ops import DropIndexOp
65
+ from .ops import DropTableCommentOp
66
+ from .ops import DropTableOp
67
+ from .ops import ExecuteSQLOp
50
68
  from .ops import MigrateOperation
51
69
  from ..ddl import DefaultImpl
52
70
  from ..runtime.migration import MigrationContext
53
71
  __all__ = ("Operations", "BatchOperations")
54
72
  _T = TypeVar("_T")
55
73
 
74
+ _C = TypeVar("_C", bound=Callable[..., Any])
75
+
56
76
 
57
77
  class AbstractOperations(util.ModuleClsProxy):
58
78
  """Base class for Operations and BatchOperations.
@@ -86,7 +106,7 @@ class AbstractOperations(util.ModuleClsProxy):
86
106
  @classmethod
87
107
  def register_operation(
88
108
  cls, name: str, sourcename: Optional[str] = None
89
- ) -> Callable[[_T], _T]:
109
+ ) -> Callable[[Type[_T]], Type[_T]]:
90
110
  """Register a new operation for this class.
91
111
 
92
112
  This method is normally used to add new operations
@@ -103,7 +123,7 @@ class AbstractOperations(util.ModuleClsProxy):
103
123
 
104
124
  """
105
125
 
106
- def register(op_cls):
126
+ def register(op_cls: Type[_T]) -> Type[_T]:
107
127
  if sourcename is None:
108
128
  fn = getattr(op_cls, name)
109
129
  source_name = fn.__name__
@@ -122,8 +142,11 @@ class AbstractOperations(util.ModuleClsProxy):
122
142
  *spec, formatannotation=formatannotation_fwdref
123
143
  )
124
144
  num_defaults = len(spec[3]) if spec[3] else 0
145
+
146
+ defaulted_vals: Tuple[Any, ...]
147
+
125
148
  if num_defaults:
126
- defaulted_vals = name_args[0 - num_defaults :]
149
+ defaulted_vals = tuple(name_args[0 - num_defaults :])
127
150
  else:
128
151
  defaulted_vals = ()
129
152
 
@@ -164,7 +187,7 @@ class AbstractOperations(util.ModuleClsProxy):
164
187
 
165
188
  globals_ = dict(globals())
166
189
  globals_.update({"op_cls": op_cls})
167
- lcl = {}
190
+ lcl: Dict[str, Any] = {}
168
191
 
169
192
  exec(func_text, globals_, lcl)
170
193
  setattr(cls, name, lcl[name])
@@ -180,7 +203,7 @@ class AbstractOperations(util.ModuleClsProxy):
180
203
  return register
181
204
 
182
205
  @classmethod
183
- def implementation_for(cls, op_cls: Any) -> Callable[..., Any]:
206
+ def implementation_for(cls, op_cls: Any) -> Callable[[_C], _C]:
184
207
  """Register an implementation for a given :class:`.MigrateOperation`.
185
208
 
186
209
  This is part of the operation extensibility API.
@@ -191,7 +214,7 @@ class AbstractOperations(util.ModuleClsProxy):
191
214
 
192
215
  """
193
216
 
194
- def decorate(fn):
217
+ def decorate(fn: _C) -> _C:
195
218
  cls._to_impl.dispatch_for(op_cls)(fn)
196
219
  return fn
197
220
 
@@ -213,7 +236,7 @@ class AbstractOperations(util.ModuleClsProxy):
213
236
  table_name: str,
214
237
  schema: Optional[str] = None,
215
238
  recreate: Literal["auto", "always", "never"] = "auto",
216
- partial_reordering: Optional[tuple] = None,
239
+ partial_reordering: Optional[Tuple[Any, ...]] = None,
217
240
  copy_from: Optional[Table] = None,
218
241
  table_args: Tuple[Any, ...] = (),
219
242
  table_kwargs: Mapping[str, Any] = util.immutabledict(),
@@ -382,6 +405,32 @@ class AbstractOperations(util.ModuleClsProxy):
382
405
 
383
406
  return self.migration_context
384
407
 
408
+ @overload
409
+ def invoke(self, operation: CreateTableOp) -> Table: ...
410
+
411
+ @overload
412
+ def invoke(
413
+ self,
414
+ operation: Union[
415
+ AddConstraintOp,
416
+ DropConstraintOp,
417
+ CreateIndexOp,
418
+ DropIndexOp,
419
+ AddColumnOp,
420
+ AlterColumnOp,
421
+ AlterTableOp,
422
+ CreateTableCommentOp,
423
+ DropTableCommentOp,
424
+ DropColumnOp,
425
+ BulkInsertOp,
426
+ DropTableOp,
427
+ ExecuteSQLOp,
428
+ ],
429
+ ) -> None: ...
430
+
431
+ @overload
432
+ def invoke(self, operation: MigrateOperation) -> Any: ...
433
+
385
434
  def invoke(self, operation: MigrateOperation) -> Any:
386
435
  """Given a :class:`.MigrateOperation`, invoke it in terms of
387
436
  this :class:`.Operations` instance.
@@ -659,8 +708,10 @@ class Operations(AbstractOperations):
659
708
  comment: Union[str, Literal[False], None] = False,
660
709
  server_default: Any = False,
661
710
  new_column_name: Optional[str] = None,
662
- type_: Union[TypeEngine, Type[TypeEngine], None] = None,
663
- existing_type: Union[TypeEngine, Type[TypeEngine], None] = None,
711
+ type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
712
+ existing_type: Union[
713
+ TypeEngine[Any], Type[TypeEngine[Any]], None
714
+ ] = None,
664
715
  existing_server_default: Union[
665
716
  str, bool, Identity, Computed, None
666
717
  ] = False,
@@ -756,7 +807,7 @@ class Operations(AbstractOperations):
756
807
  def bulk_insert(
757
808
  self,
758
809
  table: Union[Table, TableClause],
759
- rows: List[dict],
810
+ rows: List[Dict[str, Any]],
760
811
  *,
761
812
  multiinsert: bool = True,
762
813
  ) -> None:
@@ -1560,7 +1611,7 @@ class BatchOperations(AbstractOperations):
1560
1611
 
1561
1612
  impl: BatchOperationsImpl
1562
1613
 
1563
- def _noop(self, operation):
1614
+ def _noop(self, operation: Any) -> NoReturn:
1564
1615
  raise NotImplementedError(
1565
1616
  "The %s method does not apply to a batch table alter operation."
1566
1617
  % operation
@@ -1596,8 +1647,10 @@ class BatchOperations(AbstractOperations):
1596
1647
  comment: Union[str, Literal[False], None] = False,
1597
1648
  server_default: Any = False,
1598
1649
  new_column_name: Optional[str] = None,
1599
- type_: Union[TypeEngine, Type[TypeEngine], None] = None,
1600
- existing_type: Union[TypeEngine, Type[TypeEngine], None] = None,
1650
+ type_: Union[TypeEngine[Any], Type[TypeEngine[Any]], None] = None,
1651
+ existing_type: Union[
1652
+ TypeEngine[Any], Type[TypeEngine[Any]], None
1653
+ ] = None,
1601
1654
  existing_server_default: Union[
1602
1655
  str, bool, Identity, Computed, None
1603
1656
  ] = False,
@@ -1652,7 +1705,7 @@ class BatchOperations(AbstractOperations):
1652
1705
 
1653
1706
  def create_exclude_constraint(
1654
1707
  self, constraint_name: str, *elements: Any, **kw: Any
1655
- ):
1708
+ ) -> Optional[Table]:
1656
1709
  """Issue a "create exclude constraint" instruction using the
1657
1710
  current batch migration context.
1658
1711
 
@@ -1668,7 +1721,7 @@ class BatchOperations(AbstractOperations):
1668
1721
 
1669
1722
  def create_foreign_key(
1670
1723
  self,
1671
- constraint_name: str,
1724
+ constraint_name: Optional[str],
1672
1725
  referent_table: str,
1673
1726
  local_cols: List[str],
1674
1727
  remote_cols: List[str],
@@ -1718,7 +1771,7 @@ class BatchOperations(AbstractOperations):
1718
1771
  ...
1719
1772
 
1720
1773
  def create_primary_key(
1721
- self, constraint_name: str, columns: List[str]
1774
+ self, constraint_name: Optional[str], columns: List[str]
1722
1775
  ) -> None:
1723
1776
  """Issue a "create primary key" instruction using the
1724
1777
  current batch migration context.
@@ -1,3 +1,6 @@
1
+ # mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
2
+ # mypy: no-warn-return-any, allow-any-generics
3
+
1
4
  from __future__ import annotations
2
5
 
3
6
  from typing import Any
@@ -17,7 +20,7 @@ from sqlalchemy import PrimaryKeyConstraint
17
20
  from sqlalchemy import schema as sql_schema
18
21
  from sqlalchemy import Table
19
22
  from sqlalchemy import types as sqltypes
20
- from sqlalchemy.events import SchemaEventTarget
23
+ from sqlalchemy.sql.schema import SchemaEventTarget
21
24
  from sqlalchemy.util import OrderedDict
22
25
  from sqlalchemy.util import topological
23
26
 
@@ -374,7 +377,7 @@ class ApplyBatchImpl:
374
377
  for idx_existing in self.indexes.values():
375
378
  # this is a lift-and-move from Table.to_metadata
376
379
 
377
- if idx_existing._column_flag: # type: ignore
380
+ if idx_existing._column_flag:
378
381
  continue
379
382
 
380
383
  idx_copy = Index(
@@ -403,9 +406,7 @@ class ApplyBatchImpl:
403
406
  def _setup_referent(
404
407
  self, metadata: MetaData, constraint: ForeignKeyConstraint
405
408
  ) -> None:
406
- spec = constraint.elements[
407
- 0
408
- ]._get_colspec() # type:ignore[attr-defined]
409
+ spec = constraint.elements[0]._get_colspec()
409
410
  parts = spec.split(".")
410
411
  tname = parts[-2]
411
412
  if len(parts) == 3:
@@ -546,9 +547,7 @@ class ApplyBatchImpl:
546
547
  else:
547
548
  sql_schema.DefaultClause(
548
549
  server_default # type: ignore[arg-type]
549
- )._set_parent( # type:ignore[attr-defined]
550
- existing
551
- )
550
+ )._set_parent(existing)
552
551
  if autoincrement is not None:
553
552
  existing.autoincrement = bool(autoincrement)
554
553
 
alembic/operations/ops.py CHANGED
@@ -5,6 +5,7 @@ import re
5
5
  from typing import Any
6
6
  from typing import Callable
7
7
  from typing import cast
8
+ from typing import Dict
8
9
  from typing import FrozenSet
9
10
  from typing import Iterator
10
11
  from typing import List
@@ -15,6 +16,7 @@ from typing import Set
15
16
  from typing import Tuple
16
17
  from typing import Type
17
18
  from typing import TYPE_CHECKING
19
+ from typing import TypeVar
18
20
  from typing import Union
19
21
 
20
22
  from sqlalchemy.types import NULLTYPE
@@ -53,6 +55,9 @@ if TYPE_CHECKING:
53
55
  from ..runtime.migration import MigrationContext
54
56
  from ..script.revision import _RevIdType
55
57
 
58
+ _T = TypeVar("_T", bound=Any)
59
+ _AC = TypeVar("_AC", bound="AddConstraintOp")
60
+
56
61
 
57
62
  class MigrateOperation:
58
63
  """base class for migration command and organization objects.
@@ -70,7 +75,7 @@ class MigrateOperation:
70
75
  """
71
76
 
72
77
  @util.memoized_property
73
- def info(self):
78
+ def info(self) -> Dict[Any, Any]:
74
79
  """A dictionary that may be used to store arbitrary information
75
80
  along with this :class:`.MigrateOperation` object.
76
81
 
@@ -92,12 +97,14 @@ class AddConstraintOp(MigrateOperation):
92
97
  add_constraint_ops = util.Dispatcher()
93
98
 
94
99
  @property
95
- def constraint_type(self):
100
+ def constraint_type(self) -> str:
96
101
  raise NotImplementedError()
97
102
 
98
103
  @classmethod
99
- def register_add_constraint(cls, type_: str) -> Callable:
100
- def go(klass):
104
+ def register_add_constraint(
105
+ cls, type_: str
106
+ ) -> Callable[[Type[_AC]], Type[_AC]]:
107
+ def go(klass: Type[_AC]) -> Type[_AC]:
101
108
  cls.add_constraint_ops.dispatch_for(type_)(klass.from_constraint)
102
109
  return klass
103
110
 
@@ -105,7 +112,7 @@ class AddConstraintOp(MigrateOperation):
105
112
 
106
113
  @classmethod
107
114
  def from_constraint(cls, constraint: Constraint) -> AddConstraintOp:
108
- return cls.add_constraint_ops.dispatch(constraint.__visit_name__)(
115
+ return cls.add_constraint_ops.dispatch(constraint.__visit_name__)( # type: ignore[no-any-return] # noqa: E501
109
116
  constraint
110
117
  )
111
118
 
@@ -342,7 +349,7 @@ class CreatePrimaryKeyOp(AddConstraintOp):
342
349
  def batch_create_primary_key(
343
350
  cls,
344
351
  operations: BatchOperations,
345
- constraint_name: str,
352
+ constraint_name: Optional[str],
346
353
  columns: List[str],
347
354
  ) -> None:
348
355
  """Issue a "create primary key" instruction using the
@@ -398,7 +405,7 @@ class CreateUniqueConstraintOp(AddConstraintOp):
398
405
 
399
406
  uq_constraint = cast("UniqueConstraint", constraint)
400
407
 
401
- kw: dict = {}
408
+ kw: Dict[str, Any] = {}
402
409
  if uq_constraint.deferrable:
403
410
  kw["deferrable"] = uq_constraint.deferrable
404
411
  if uq_constraint.initially:
@@ -532,7 +539,7 @@ class CreateForeignKeyOp(AddConstraintOp):
532
539
  @classmethod
533
540
  def from_constraint(cls, constraint: Constraint) -> CreateForeignKeyOp:
534
541
  fk_constraint = cast("ForeignKeyConstraint", constraint)
535
- kw: dict = {}
542
+ kw: Dict[str, Any] = {}
536
543
  if fk_constraint.onupdate:
537
544
  kw["onupdate"] = fk_constraint.onupdate
538
545
  if fk_constraint.ondelete:
@@ -674,7 +681,7 @@ class CreateForeignKeyOp(AddConstraintOp):
674
681
  def batch_create_foreign_key(
675
682
  cls,
676
683
  operations: BatchOperations,
677
- constraint_name: str,
684
+ constraint_name: Optional[str],
678
685
  referent_table: str,
679
686
  local_cols: List[str],
680
687
  remote_cols: List[str],
@@ -897,7 +904,7 @@ class CreateIndexOp(MigrateOperation):
897
904
  def from_index(cls, index: Index) -> CreateIndexOp:
898
905
  assert index.table is not None
899
906
  return cls(
900
- index.name, # type: ignore[arg-type]
907
+ index.name,
901
908
  index.table.name,
902
909
  index.expressions,
903
910
  schema=index.table.schema,
@@ -1054,6 +1061,7 @@ class DropIndexOp(MigrateOperation):
1054
1061
  table_name=index.table.name,
1055
1062
  schema=index.table.schema,
1056
1063
  _reverse=CreateIndexOp.from_index(index),
1064
+ unique=index.unique,
1057
1065
  **index.kwargs,
1058
1066
  )
1059
1067
 
@@ -1182,7 +1190,7 @@ class CreateTableOp(MigrateOperation):
1182
1190
 
1183
1191
  return cls(
1184
1192
  table.name,
1185
- list(table.c) + list(table.constraints), # type:ignore[arg-type]
1193
+ list(table.c) + list(table.constraints),
1186
1194
  schema=table.schema,
1187
1195
  _namespace_metadata=_namespace_metadata,
1188
1196
  # given a Table() object, this Table will contain full Index()
@@ -1363,9 +1371,9 @@ class DropTableOp(MigrateOperation):
1363
1371
  info=self.info.copy() if self.info else {},
1364
1372
  prefixes=list(self.prefixes) if self.prefixes else [],
1365
1373
  schema=self.schema,
1366
- _constraints_included=self._reverse._constraints_included
1367
- if self._reverse
1368
- else False,
1374
+ _constraints_included=(
1375
+ self._reverse._constraints_included if self._reverse else False
1376
+ ),
1369
1377
  **self.table_kw,
1370
1378
  )
1371
1379
  return t
@@ -1534,7 +1542,7 @@ class CreateTableCommentOp(AlterTableOp):
1534
1542
  )
1535
1543
  return operations.invoke(op)
1536
1544
 
1537
- def reverse(self):
1545
+ def reverse(self) -> Union[CreateTableCommentOp, DropTableCommentOp]:
1538
1546
  """Reverses the COMMENT ON operation against a table."""
1539
1547
  if self.existing_comment is None:
1540
1548
  return DropTableCommentOp(
@@ -1550,14 +1558,16 @@ class CreateTableCommentOp(AlterTableOp):
1550
1558
  schema=self.schema,
1551
1559
  )
1552
1560
 
1553
- def to_table(self, migration_context=None):
1561
+ def to_table(
1562
+ self, migration_context: Optional[MigrationContext] = None
1563
+ ) -> Table:
1554
1564
  schema_obj = schemaobj.SchemaObjects(migration_context)
1555
1565
 
1556
1566
  return schema_obj.table(
1557
1567
  self.table_name, schema=self.schema, comment=self.comment
1558
1568
  )
1559
1569
 
1560
- def to_diff_tuple(self):
1570
+ def to_diff_tuple(self) -> Tuple[Any, ...]:
1561
1571
  return ("add_table_comment", self.to_table(), self.existing_comment)
1562
1572
 
1563
1573
 
@@ -1629,18 +1639,20 @@ class DropTableCommentOp(AlterTableOp):
1629
1639
  )
1630
1640
  return operations.invoke(op)
1631
1641
 
1632
- def reverse(self):
1642
+ def reverse(self) -> CreateTableCommentOp:
1633
1643
  """Reverses the COMMENT ON operation against a table."""
1634
1644
  return CreateTableCommentOp(
1635
1645
  self.table_name, self.existing_comment, schema=self.schema
1636
1646
  )
1637
1647
 
1638
- def to_table(self, migration_context=None):
1648
+ def to_table(
1649
+ self, migration_context: Optional[MigrationContext] = None
1650
+ ) -> Table:
1639
1651
  schema_obj = schemaobj.SchemaObjects(migration_context)
1640
1652
 
1641
1653
  return schema_obj.table(self.table_name, schema=self.schema)
1642
1654
 
1643
- def to_diff_tuple(self):
1655
+ def to_diff_tuple(self) -> Tuple[Any, ...]:
1644
1656
  return ("remove_table_comment", self.to_table())
1645
1657
 
1646
1658
 
@@ -1817,8 +1829,10 @@ class AlterColumnOp(AlterTableOp):
1817
1829
  comment: Optional[Union[str, Literal[False]]] = False,
1818
1830
  server_default: Any = False,
1819
1831
  new_column_name: Optional[str] = None,
1820
- type_: Optional[Union[TypeEngine, Type[TypeEngine]]] = None,
1821
- existing_type: Optional[Union[TypeEngine, Type[TypeEngine]]] = None,
1832
+ type_: Optional[Union[TypeEngine[Any], Type[TypeEngine[Any]]]] = None,
1833
+ existing_type: Optional[
1834
+ Union[TypeEngine[Any], Type[TypeEngine[Any]]]
1835
+ ] = None,
1822
1836
  existing_server_default: Optional[
1823
1837
  Union[str, bool, Identity, Computed]
1824
1838
  ] = False,
@@ -1938,8 +1952,10 @@ class AlterColumnOp(AlterTableOp):
1938
1952
  comment: Optional[Union[str, Literal[False]]] = False,
1939
1953
  server_default: Any = False,
1940
1954
  new_column_name: Optional[str] = None,
1941
- type_: Optional[Union[TypeEngine, Type[TypeEngine]]] = None,
1942
- existing_type: Optional[Union[TypeEngine, Type[TypeEngine]]] = None,
1955
+ type_: Optional[Union[TypeEngine[Any], Type[TypeEngine[Any]]]] = None,
1956
+ existing_type: Optional[
1957
+ Union[TypeEngine[Any], Type[TypeEngine[Any]]]
1958
+ ] = None,
1943
1959
  existing_server_default: Optional[
1944
1960
  Union[str, bool, Identity, Computed]
1945
1961
  ] = False,
@@ -2019,11 +2035,11 @@ class AddColumnOp(AlterTableOp):
2019
2035
  ) -> Tuple[str, Optional[str], str, Column[Any]]:
2020
2036
  return ("add_column", self.schema, self.table_name, self.column)
2021
2037
 
2022
- def to_column(self) -> Column:
2038
+ def to_column(self) -> Column[Any]:
2023
2039
  return self.column
2024
2040
 
2025
2041
  @classmethod
2026
- def from_column(cls, col: Column) -> AddColumnOp:
2042
+ def from_column(cls, col: Column[Any]) -> AddColumnOp:
2027
2043
  return cls(col.table.name, col, schema=col.table.schema)
2028
2044
 
2029
2045
  @classmethod
@@ -2214,7 +2230,7 @@ class DropColumnOp(AlterTableOp):
2214
2230
 
2215
2231
  def to_column(
2216
2232
  self, migration_context: Optional[MigrationContext] = None
2217
- ) -> Column:
2233
+ ) -> Column[Any]:
2218
2234
  if self._reverse is not None:
2219
2235
  return self._reverse.column
2220
2236
  schema_obj = schemaobj.SchemaObjects(migration_context)
@@ -2298,7 +2314,7 @@ class BulkInsertOp(MigrateOperation):
2298
2314
  def __init__(
2299
2315
  self,
2300
2316
  table: Union[Table, TableClause],
2301
- rows: List[dict],
2317
+ rows: List[Dict[str, Any]],
2302
2318
  *,
2303
2319
  multiinsert: bool = True,
2304
2320
  ) -> None:
@@ -2311,7 +2327,7 @@ class BulkInsertOp(MigrateOperation):
2311
2327
  cls,
2312
2328
  operations: Operations,
2313
2329
  table: Union[Table, TableClause],
2314
- rows: List[dict],
2330
+ rows: List[Dict[str, Any]],
2315
2331
  *,
2316
2332
  multiinsert: bool = True,
2317
2333
  ) -> None:
@@ -2607,7 +2623,7 @@ class UpgradeOps(OpContainer):
2607
2623
  self.upgrade_token = upgrade_token
2608
2624
 
2609
2625
  def reverse_into(self, downgrade_ops: DowngradeOps) -> DowngradeOps:
2610
- downgrade_ops.ops[:] = list( # type:ignore[index]
2626
+ downgrade_ops.ops[:] = list(
2611
2627
  reversed([op.reverse() for op in self.ops])
2612
2628
  )
2613
2629
  return downgrade_ops
@@ -2634,7 +2650,7 @@ class DowngradeOps(OpContainer):
2634
2650
  super().__init__(ops=ops)
2635
2651
  self.downgrade_token = downgrade_token
2636
2652
 
2637
- def reverse(self):
2653
+ def reverse(self) -> UpgradeOps:
2638
2654
  return UpgradeOps(
2639
2655
  ops=list(reversed([op.reverse() for op in self.ops]))
2640
2656
  )
@@ -2665,6 +2681,8 @@ class MigrationScript(MigrateOperation):
2665
2681
  """
2666
2682
 
2667
2683
  _needs_render: Optional[bool]
2684
+ _upgrade_ops: List[UpgradeOps]
2685
+ _downgrade_ops: List[DowngradeOps]
2668
2686
 
2669
2687
  def __init__(
2670
2688
  self,
@@ -2692,7 +2710,7 @@ class MigrationScript(MigrateOperation):
2692
2710
  self.downgrade_ops = downgrade_ops
2693
2711
 
2694
2712
  @property
2695
- def upgrade_ops(self):
2713
+ def upgrade_ops(self) -> Optional[UpgradeOps]:
2696
2714
  """An instance of :class:`.UpgradeOps`.
2697
2715
 
2698
2716
  .. seealso::
@@ -2711,13 +2729,15 @@ class MigrationScript(MigrateOperation):
2711
2729
  return self._upgrade_ops[0]
2712
2730
 
2713
2731
  @upgrade_ops.setter
2714
- def upgrade_ops(self, upgrade_ops):
2732
+ def upgrade_ops(
2733
+ self, upgrade_ops: Union[UpgradeOps, List[UpgradeOps]]
2734
+ ) -> None:
2715
2735
  self._upgrade_ops = util.to_list(upgrade_ops)
2716
2736
  for elem in self._upgrade_ops:
2717
2737
  assert isinstance(elem, UpgradeOps)
2718
2738
 
2719
2739
  @property
2720
- def downgrade_ops(self):
2740
+ def downgrade_ops(self) -> Optional[DowngradeOps]:
2721
2741
  """An instance of :class:`.DowngradeOps`.
2722
2742
 
2723
2743
  .. seealso::
@@ -2736,7 +2756,9 @@ class MigrationScript(MigrateOperation):
2736
2756
  return self._downgrade_ops[0]
2737
2757
 
2738
2758
  @downgrade_ops.setter
2739
- def downgrade_ops(self, downgrade_ops):
2759
+ def downgrade_ops(
2760
+ self, downgrade_ops: Union[DowngradeOps, List[DowngradeOps]]
2761
+ ) -> None:
2740
2762
  self._downgrade_ops = util.to_list(downgrade_ops)
2741
2763
  for elem in self._downgrade_ops:
2742
2764
  assert isinstance(elem, DowngradeOps)