alembic 1.11.0__py3-none-any.whl → 1.11.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 (40) hide show
  1. alembic/__init__.py +1 -1
  2. alembic/autogenerate/api.py +0 -2
  3. alembic/autogenerate/compare.py +24 -35
  4. alembic/autogenerate/render.py +24 -38
  5. alembic/command.py +0 -1
  6. alembic/config.py +20 -7
  7. alembic/context.pyi +2 -2
  8. alembic/ddl/base.py +3 -3
  9. alembic/ddl/impl.py +14 -9
  10. alembic/ddl/mssql.py +8 -9
  11. alembic/ddl/mysql.py +0 -1
  12. alembic/ddl/oracle.py +1 -1
  13. alembic/ddl/postgresql.py +35 -12
  14. alembic/ddl/sqlite.py +3 -5
  15. alembic/op.pyi +32 -20
  16. alembic/operations/base.py +34 -22
  17. alembic/operations/batch.py +10 -8
  18. alembic/operations/ops.py +60 -36
  19. alembic/operations/toimpl.py +18 -4
  20. alembic/runtime/environment.py +2 -3
  21. alembic/runtime/migration.py +3 -7
  22. alembic/script/base.py +3 -7
  23. alembic/script/revision.py +0 -4
  24. alembic/script/write_hooks.py +8 -7
  25. alembic/templates/async/script.py.mako +6 -4
  26. alembic/templates/generic/script.py.mako +6 -4
  27. alembic/templates/multidb/script.py.mako +6 -4
  28. alembic/testing/assertions.py +0 -3
  29. alembic/testing/env.py +0 -3
  30. alembic/testing/fixtures.py +0 -2
  31. alembic/testing/suite/_autogen_fixtures.py +0 -1
  32. alembic/util/langhelpers.py +0 -1
  33. alembic/util/pyfiles.py +0 -1
  34. alembic/util/sqla_compat.py +4 -5
  35. {alembic-1.11.0.dist-info → alembic-1.11.2.dist-info}/METADATA +1 -1
  36. {alembic-1.11.0.dist-info → alembic-1.11.2.dist-info}/RECORD +40 -40
  37. {alembic-1.11.0.dist-info → alembic-1.11.2.dist-info}/WHEEL +1 -1
  38. {alembic-1.11.0.dist-info → alembic-1.11.2.dist-info}/LICENSE +0 -0
  39. {alembic-1.11.0.dist-info → alembic-1.11.2.dist-info}/entry_points.txt +0 -0
  40. {alembic-1.11.0.dist-info → alembic-1.11.2.dist-info}/top_level.txt +0 -0
alembic/__init__.py CHANGED
@@ -3,4 +3,4 @@ import sys
3
3
  from . import context
4
4
  from . import op
5
5
 
6
- __version__ = "1.11.0"
6
+ __version__ = "1.11.2"
@@ -331,7 +331,6 @@ class AutogenContext:
331
331
  opts: Optional[dict] = None,
332
332
  autogenerate: bool = True,
333
333
  ) -> None:
334
-
335
334
  if (
336
335
  autogenerate
337
336
  and migration_context is not None
@@ -431,7 +430,6 @@ class AutogenContext:
431
430
  parent_names["schema_qualified_table_name"] = table_name
432
431
 
433
432
  for fn in self._name_filters:
434
-
435
433
  if not fn(name, type_, parent_names):
436
434
  return False
437
435
  else:
@@ -66,7 +66,6 @@ comparators = util.Dispatcher(uselist=True)
66
66
  def _produce_net_changes(
67
67
  autogen_context: AutogenContext, upgrade_ops: UpgradeOps
68
68
  ) -> None:
69
-
70
69
  connection = autogen_context.connection
71
70
  assert connection is not None
72
71
  include_schemas = autogen_context.opts.get("include_schemas", False)
@@ -145,7 +144,6 @@ def _compare_tables(
145
144
  upgrade_ops: UpgradeOps,
146
145
  autogen_context: AutogenContext,
147
146
  ) -> None:
148
-
149
147
  default_schema = inspector.bind.dialect.default_schema_name
150
148
 
151
149
  # tables coming from the connection will not have "schema"
@@ -214,7 +212,6 @@ def _compare_tables(
214
212
  )
215
213
  sqla_compat._reflect_table(inspector, t)
216
214
  if autogen_context.run_object_filters(t, tname, "table", True, None):
217
-
218
215
  modify_table_ops = ops.ModifyTableOps(tname, [], schema=s)
219
216
 
220
217
  comparators.dispatch("table")(
@@ -255,7 +252,6 @@ def _compare_tables(
255
252
  if autogen_context.run_object_filters(
256
253
  metadata_table, tname, "table", False, conn_table
257
254
  ):
258
-
259
255
  modify_table_ops = ops.ModifyTableOps(tname, [], schema=s)
260
256
  with _compare_columns(
261
257
  s,
@@ -266,7 +262,6 @@ def _compare_tables(
266
262
  autogen_context,
267
263
  inspector,
268
264
  ):
269
-
270
265
  comparators.dispatch("table")(
271
266
  autogen_context,
272
267
  modify_table_ops,
@@ -449,11 +444,11 @@ class _uq_constraint_sig(_constraint_sig):
449
444
  is_index = False
450
445
  is_unique = True
451
446
 
452
- def __init__(self, const: UniqueConstraint) -> None:
447
+ def __init__(self, const: UniqueConstraint, impl: DefaultImpl) -> None:
453
448
  self.const = const
454
449
  self.name = const.name
455
- self.sig = ("UNIQUE_CONSTRAINT",) + tuple(
456
- sorted([col.name for col in const.columns])
450
+ self.sig = ("UNIQUE_CONSTRAINT",) + impl.create_unique_constraint_sig(
451
+ const
457
452
  )
458
453
 
459
454
  @property
@@ -534,7 +529,6 @@ def _compare_indexes_and_uniques(
534
529
  conn_table: Optional[Table],
535
530
  metadata_table: Optional[Table],
536
531
  ) -> None:
537
-
538
532
  inspector = autogen_context.inspector
539
533
  is_create_table = conn_table is None
540
534
  is_drop_table = metadata_table is None
@@ -622,6 +616,7 @@ def _compare_indexes_and_uniques(
622
616
  # 2a. if the dialect dupes unique indexes as unique constraints
623
617
  # (mysql and oracle), correct for that
624
618
 
619
+ impl = autogen_context.migration_context.impl
625
620
  if unique_constraints_duplicate_unique_indexes:
626
621
  _correct_for_uq_duplicates_uix(
627
622
  conn_uniques,
@@ -629,6 +624,7 @@ def _compare_indexes_and_uniques(
629
624
  metadata_unique_constraints,
630
625
  metadata_indexes,
631
626
  autogen_context.dialect,
627
+ impl,
632
628
  )
633
629
 
634
630
  # 3. give the dialect a chance to omit indexes and constraints that
@@ -646,15 +642,16 @@ def _compare_indexes_and_uniques(
646
642
  # Index and UniqueConstraint so we can easily work with them
647
643
  # interchangeably
648
644
  metadata_unique_constraints_sig = {
649
- _uq_constraint_sig(uq) for uq in metadata_unique_constraints
645
+ _uq_constraint_sig(uq, impl) for uq in metadata_unique_constraints
650
646
  }
651
647
 
652
- impl = autogen_context.migration_context.impl
653
648
  metadata_indexes_sig = {
654
649
  _ix_constraint_sig(ix, impl) for ix in metadata_indexes
655
650
  }
656
651
 
657
- conn_unique_constraints = {_uq_constraint_sig(uq) for uq in conn_uniques}
652
+ conn_unique_constraints = {
653
+ _uq_constraint_sig(uq, impl) for uq in conn_uniques
654
+ }
658
655
 
659
656
  conn_indexes_sig = {_ix_constraint_sig(ix, impl) for ix in conn_indexes}
660
657
 
@@ -864,6 +861,7 @@ def _correct_for_uq_duplicates_uix(
864
861
  metadata_unique_constraints,
865
862
  metadata_indexes,
866
863
  dialect,
864
+ impl,
867
865
  ):
868
866
  # dedupe unique indexes vs. constraints, since MySQL / Oracle
869
867
  # doesn't really have unique constraints as a separate construct.
@@ -886,7 +884,7 @@ def _correct_for_uq_duplicates_uix(
886
884
  }
887
885
 
888
886
  unnamed_metadata_uqs = {
889
- _uq_constraint_sig(cons).sig
887
+ _uq_constraint_sig(cons, impl).sig
890
888
  for name, cons in metadata_cons_names
891
889
  if name is None
892
890
  }
@@ -910,10 +908,9 @@ def _correct_for_uq_duplicates_uix(
910
908
  for overlap in uqs_dupe_indexes:
911
909
  if overlap not in metadata_uq_names:
912
910
  if (
913
- _uq_constraint_sig(uqs_dupe_indexes[overlap]).sig
911
+ _uq_constraint_sig(uqs_dupe_indexes[overlap], impl).sig
914
912
  not in unnamed_metadata_uqs
915
913
  ):
916
-
917
914
  conn_unique_constraints.discard(uqs_dupe_indexes[overlap])
918
915
  elif overlap not in metadata_ix_names:
919
916
  conn_indexes.discard(conn_ix_names[overlap])
@@ -926,10 +923,9 @@ def _compare_nullable(
926
923
  schema: Optional[str],
927
924
  tname: Union[quoted_name, str],
928
925
  cname: Union[quoted_name, str],
929
- conn_col: Column,
930
- metadata_col: Column,
926
+ conn_col: Column[Any],
927
+ metadata_col: Column[Any],
931
928
  ) -> None:
932
-
933
929
  metadata_col_nullable = metadata_col.nullable
934
930
  conn_col_nullable = conn_col.nullable
935
931
  alter_column_op.existing_nullable = conn_col_nullable
@@ -968,10 +964,9 @@ def _setup_autoincrement(
968
964
  schema: Optional[str],
969
965
  tname: Union[quoted_name, str],
970
966
  cname: quoted_name,
971
- conn_col: Column,
972
- metadata_col: Column,
967
+ conn_col: Column[Any],
968
+ metadata_col: Column[Any],
973
969
  ) -> None:
974
-
975
970
  if metadata_col.table._autoincrement_column is metadata_col:
976
971
  alter_column_op.kw["autoincrement"] = True
977
972
  elif metadata_col.autoincrement is True:
@@ -987,10 +982,9 @@ def _compare_type(
987
982
  schema: Optional[str],
988
983
  tname: Union[quoted_name, str],
989
984
  cname: Union[quoted_name, str],
990
- conn_col: Column,
991
- metadata_col: Column,
985
+ conn_col: Column[Any],
986
+ metadata_col: Column[Any],
992
987
  ) -> None:
993
-
994
988
  conn_type = conn_col.type
995
989
  alter_column_op.existing_type = conn_type
996
990
  metadata_type = metadata_col.type
@@ -1027,7 +1021,6 @@ def _compare_type(
1027
1021
  def _render_server_default_for_compare(
1028
1022
  metadata_default: Optional[Any], autogen_context: AutogenContext
1029
1023
  ) -> Optional[str]:
1030
-
1031
1024
  if isinstance(metadata_default, sa_schema.DefaultClause):
1032
1025
  if isinstance(metadata_default.arg, str):
1033
1026
  metadata_default = metadata_default.arg
@@ -1060,8 +1053,8 @@ def _compare_computed_default(
1060
1053
  schema: Optional[str],
1061
1054
  tname: str,
1062
1055
  cname: str,
1063
- conn_col: Column,
1064
- metadata_col: Column,
1056
+ conn_col: Column[Any],
1057
+ metadata_col: Column[Any],
1065
1058
  ) -> None:
1066
1059
  rendered_metadata_default = str(
1067
1060
  cast(sa_schema.Computed, metadata_col.server_default).sqltext.compile(
@@ -1126,10 +1119,9 @@ def _compare_server_default(
1126
1119
  schema: Optional[str],
1127
1120
  tname: Union[quoted_name, str],
1128
1121
  cname: Union[quoted_name, str],
1129
- conn_col: Column,
1130
- metadata_col: Column,
1122
+ conn_col: Column[Any],
1123
+ metadata_col: Column[Any],
1131
1124
  ) -> Optional[bool]:
1132
-
1133
1125
  metadata_default = metadata_col.server_default
1134
1126
  conn_col_default = conn_col.server_default
1135
1127
  if conn_col_default is None and metadata_default is None:
@@ -1215,10 +1207,9 @@ def _compare_column_comment(
1215
1207
  schema: Optional[str],
1216
1208
  tname: Union[quoted_name, str],
1217
1209
  cname: quoted_name,
1218
- conn_col: Column,
1219
- metadata_col: Column,
1210
+ conn_col: Column[Any],
1211
+ metadata_col: Column[Any],
1220
1212
  ) -> Optional[Literal[False]]:
1221
-
1222
1213
  assert autogen_context.dialect is not None
1223
1214
  if not autogen_context.dialect.supports_comments:
1224
1215
  return None
@@ -1246,7 +1237,6 @@ def _compare_foreign_keys(
1246
1237
  conn_table: Optional[Table],
1247
1238
  metadata_table: Optional[Table],
1248
1239
  ) -> None:
1249
-
1250
1240
  # if we're doing CREATE TABLE, all FKs are created
1251
1241
  # inline within the table def
1252
1242
  if conn_table is None or metadata_table is None:
@@ -1366,7 +1356,6 @@ def _compare_table_comment(
1366
1356
  conn_table: Optional[Table],
1367
1357
  metadata_table: Optional[Table],
1368
1358
  ) -> None:
1369
-
1370
1359
  assert autogen_context.dialect is not None
1371
1360
  if not autogen_context.dialect.supports_comments:
1372
1361
  return
@@ -26,6 +26,7 @@ from ..util import sqla_compat
26
26
  if TYPE_CHECKING:
27
27
  from typing import Literal
28
28
 
29
+ from sqlalchemy.sql.base import DialectKWArgs
29
30
  from sqlalchemy.sql.elements import ColumnElement
30
31
  from sqlalchemy.sql.elements import TextClause
31
32
  from sqlalchemy.sql.schema import CheckConstraint
@@ -94,7 +95,6 @@ def _render_cmd_body(
94
95
  op_container: ops.OpContainer,
95
96
  autogen_context: AutogenContext,
96
97
  ) -> str:
97
-
98
98
  buf = StringIO()
99
99
  printer = PythonPrinter(buf)
100
100
 
@@ -165,7 +165,6 @@ def _render_modify_table(
165
165
  def _render_create_table_comment(
166
166
  autogen_context: AutogenContext, op: ops.CreateTableCommentOp
167
167
  ) -> str:
168
-
169
168
  templ = (
170
169
  "{prefix}create_table_comment(\n"
171
170
  "{indent}'{tname}',\n"
@@ -190,7 +189,6 @@ def _render_create_table_comment(
190
189
  def _render_drop_table_comment(
191
190
  autogen_context: AutogenContext, op: ops.DropTableCommentOp
192
191
  ) -> str:
193
-
194
192
  templ = (
195
193
  "{prefix}drop_table_comment(\n"
196
194
  "{indent}'{tname}',\n"
@@ -271,6 +269,15 @@ def _drop_table(autogen_context: AutogenContext, op: ops.DropTableOp) -> str:
271
269
  return text
272
270
 
273
271
 
272
+ def _render_dialect_kwargs_items(
273
+ autogen_context: AutogenContext, item: DialectKWArgs
274
+ ) -> list[str]:
275
+ return [
276
+ f"{key}={_render_potential_expr(val, autogen_context)}"
277
+ for key, val in item.dialect_kwargs.items()
278
+ ]
279
+
280
+
274
281
  @renderers.dispatch_for(ops.CreateIndexOp)
275
282
  def _add_index(autogen_context: AutogenContext, op: ops.CreateIndexOp) -> str:
276
283
  index = op.to_index()
@@ -289,6 +296,8 @@ def _add_index(autogen_context: AutogenContext, op: ops.CreateIndexOp) -> str:
289
296
  )
290
297
 
291
298
  assert index.table is not None
299
+
300
+ opts = _render_dialect_kwargs_items(autogen_context, index)
292
301
  text = tmpl % {
293
302
  "prefix": _alembic_autogenerate_prefix(autogen_context),
294
303
  "name": _render_gen_name(autogen_context, index.name),
@@ -300,18 +309,7 @@ def _add_index(autogen_context: AutogenContext, op: ops.CreateIndexOp) -> str:
300
309
  "schema": (", schema=%r" % _ident(index.table.schema))
301
310
  if index.table.schema
302
311
  else "",
303
- "kwargs": (
304
- ", "
305
- + ", ".join(
306
- [
307
- "%s=%s"
308
- % (key, _render_potential_expr(val, autogen_context))
309
- for key, val in index.kwargs.items()
310
- ]
311
- )
312
- )
313
- if len(index.kwargs)
314
- else "",
312
+ "kwargs": ", " + ", ".join(opts) if opts else "",
315
313
  }
316
314
  return text
317
315
 
@@ -329,24 +327,13 @@ def _drop_index(autogen_context: AutogenContext, op: ops.DropIndexOp) -> str:
329
327
  "%(prefix)sdrop_index(%(name)r, "
330
328
  "table_name=%(table_name)r%(schema)s%(kwargs)s)"
331
329
  )
332
-
330
+ opts = _render_dialect_kwargs_items(autogen_context, index)
333
331
  text = tmpl % {
334
332
  "prefix": _alembic_autogenerate_prefix(autogen_context),
335
333
  "name": _render_gen_name(autogen_context, op.index_name),
336
334
  "table_name": _ident(op.table_name),
337
335
  "schema": ((", schema=%r" % _ident(op.schema)) if op.schema else ""),
338
- "kwargs": (
339
- ", "
340
- + ", ".join(
341
- [
342
- "%s=%s"
343
- % (key, _render_potential_expr(val, autogen_context))
344
- for key, val in index.kwargs.items()
345
- ]
346
- )
347
- )
348
- if len(index.kwargs)
349
- else "",
336
+ "kwargs": ", " + ", ".join(opts) if opts else "",
350
337
  }
351
338
  return text
352
339
 
@@ -362,7 +349,6 @@ def _add_unique_constraint(
362
349
  def _add_fk_constraint(
363
350
  autogen_context: AutogenContext, op: ops.CreateForeignKeyOp
364
351
  ) -> str:
365
-
366
352
  args = [repr(_render_gen_name(autogen_context, op.constraint_name))]
367
353
  if not autogen_context._has_batch:
368
354
  args.append(repr(_ident(op.source_table)))
@@ -411,7 +397,6 @@ def _add_check_constraint(constraint, autogen_context):
411
397
  def _drop_constraint(
412
398
  autogen_context: AutogenContext, op: ops.DropConstraintOp
413
399
  ) -> str:
414
-
415
400
  if autogen_context._has_batch:
416
401
  template = "%(prefix)sdrop_constraint" "(%(name)r, type_=%(type)r)"
417
402
  else:
@@ -432,7 +417,6 @@ def _drop_constraint(
432
417
 
433
418
  @renderers.dispatch_for(ops.AddColumnOp)
434
419
  def _add_column(autogen_context: AutogenContext, op: ops.AddColumnOp) -> str:
435
-
436
420
  schema, tname, column = op.schema, op.table_name, op.column
437
421
  if autogen_context._has_batch:
438
422
  template = "%(prefix)sadd_column(%(column)s)"
@@ -452,7 +436,6 @@ def _add_column(autogen_context: AutogenContext, op: ops.AddColumnOp) -> str:
452
436
 
453
437
  @renderers.dispatch_for(ops.DropColumnOp)
454
438
  def _drop_column(autogen_context: AutogenContext, op: ops.DropColumnOp) -> str:
455
-
456
439
  schema, tname, column_name = op.schema, op.table_name, op.column_name
457
440
 
458
441
  if autogen_context._has_batch:
@@ -476,7 +459,6 @@ def _drop_column(autogen_context: AutogenContext, op: ops.DropColumnOp) -> str:
476
459
  def _alter_column(
477
460
  autogen_context: AutogenContext, op: ops.AlterColumnOp
478
461
  ) -> str:
479
-
480
462
  tname = op.table_name
481
463
  cname = op.column_name
482
464
  server_default = op.modify_server_default
@@ -566,7 +548,6 @@ def _render_potential_expr(
566
548
  is_server_default: bool = False,
567
549
  ) -> str:
568
550
  if isinstance(value, sql.ClauseElement):
569
-
570
551
  if wrap_in_text:
571
552
  template = "%(prefix)stext(%(sql)r)"
572
553
  else:
@@ -613,6 +594,7 @@ def _uq_constraint(
613
594
  opts.append(
614
595
  ("name", _render_gen_name(autogen_context, constraint.name))
615
596
  )
597
+ dialect_options = _render_dialect_kwargs_items(autogen_context, constraint)
616
598
 
617
599
  if alter:
618
600
  args = [repr(_render_gen_name(autogen_context, constraint.name))]
@@ -620,6 +602,7 @@ def _uq_constraint(
620
602
  args += [repr(_ident(constraint.table.name))]
621
603
  args.append(repr([_ident(col.name) for col in constraint.columns]))
622
604
  args.extend(["%s=%r" % (k, v) for k, v in opts])
605
+ args.extend(dialect_options)
623
606
  return "%(prefix)screate_unique_constraint(%(args)s)" % {
624
607
  "prefix": _alembic_autogenerate_prefix(autogen_context),
625
608
  "args": ", ".join(args),
@@ -627,6 +610,7 @@ def _uq_constraint(
627
610
  else:
628
611
  args = [repr(_ident(col.name)) for col in constraint.columns]
629
612
  args.extend(["%s=%r" % (k, v) for k, v in opts])
613
+ args.extend(dialect_options)
630
614
  return "%(prefix)sUniqueConstraint(%(args)s)" % {
631
615
  "prefix": _sqlalchemy_autogenerate_prefix(autogen_context),
632
616
  "args": ", ".join(args),
@@ -664,7 +648,9 @@ def _user_defined_render(
664
648
  return False
665
649
 
666
650
 
667
- def _render_column(column: Column, autogen_context: AutogenContext) -> str:
651
+ def _render_column(
652
+ column: Column[Any], autogen_context: AutogenContext
653
+ ) -> str:
668
654
  rendered = _user_defined_render("column", column, autogen_context)
669
655
  if rendered is not False:
670
656
  return rendered
@@ -673,7 +659,6 @@ def _render_column(column: Column, autogen_context: AutogenContext) -> str:
673
659
  opts: List[Tuple[str, Any]] = []
674
660
 
675
661
  if column.server_default:
676
-
677
662
  rendered = _render_server_default( # type:ignore[assignment]
678
663
  column.server_default, autogen_context
679
664
  )
@@ -727,7 +712,9 @@ def _should_render_server_default_positionally(server_default: Any) -> bool:
727
712
 
728
713
 
729
714
  def _render_server_default(
730
- default: Optional[Union[FetchedValue, str, TextClause, ColumnElement]],
715
+ default: Optional[
716
+ Union[FetchedValue, str, TextClause, ColumnElement[Any]]
717
+ ],
731
718
  autogen_context: AutogenContext,
732
719
  repr_: bool = True,
733
720
  ) -> Optional[str]:
@@ -980,7 +967,6 @@ def _fk_colspec(
980
967
  def _populate_render_fk_opts(
981
968
  constraint: ForeignKeyConstraint, opts: List[Tuple[str, str]]
982
969
  ) -> None:
983
-
984
970
  if constraint.onupdate:
985
971
  opts.append(("onupdate", repr(constraint.onupdate)))
986
972
  if constraint.ondelete:
alembic/command.py CHANGED
@@ -494,7 +494,6 @@ def history(
494
494
  for sc in script.walk_revisions(
495
495
  base=base or "base", head=head or "heads"
496
496
  ):
497
-
498
497
  if indicate_current:
499
498
  sc._db_current_indicator = sc.revision in currents
500
499
 
alembic/config.py CHANGED
@@ -8,6 +8,7 @@ import os
8
8
  import sys
9
9
  from typing import Any
10
10
  from typing import cast
11
+ from typing import Dict
11
12
  from typing import Mapping
12
13
  from typing import Optional
13
14
  from typing import overload
@@ -23,7 +24,6 @@ from .util import compat
23
24
 
24
25
 
25
26
  class Config:
26
-
27
27
  r"""Represent an Alembic configuration.
28
28
 
29
29
  Within an ``env.py`` script, this is available
@@ -219,20 +219,34 @@ class Config:
219
219
 
220
220
  @overload
221
221
  def get_section(
222
- self, name: str, default: Mapping[str, str]
223
- ) -> Mapping[str, str]:
222
+ self, name: str, default: None = ...
223
+ ) -> Optional[Dict[str, str]]:
224
224
  ...
225
225
 
226
+ # "default" here could also be a TypeVar
227
+ # _MT = TypeVar("_MT", bound=Mapping[str, str]),
228
+ # however mypy wasn't handling that correctly (pyright was)
226
229
  @overload
227
230
  def get_section(
228
- self, name: str, default: Optional[Mapping[str, str]] = ...
229
- ) -> Optional[Mapping[str, str]]:
231
+ self, name: str, default: Dict[str, str]
232
+ ) -> Dict[str, str]:
233
+ ...
234
+
235
+ @overload
236
+ def get_section(
237
+ self, name: str, default: Mapping[str, str]
238
+ ) -> Union[Dict[str, str], Mapping[str, str]]:
230
239
  ...
231
240
 
232
- def get_section(self, name: str, default=None):
241
+ def get_section(
242
+ self, name: str, default: Optional[Mapping[str, str]] = None
243
+ ) -> Optional[Mapping[str, str]]:
233
244
  """Return all the configuration options from a given .ini file section
234
245
  as a dictionary.
235
246
 
247
+ If the given section does not exist, the value of ``default``
248
+ is returned, which is expected to be a dictionary or other mapping.
249
+
236
250
  """
237
251
  if not self.file_config.has_section(name):
238
252
  return default
@@ -548,7 +562,6 @@ class CommandLine:
548
562
  and fn.__name__[0] != "_"
549
563
  and fn.__module__ == "alembic.command"
550
564
  ):
551
-
552
565
  spec = compat.inspect_getfullargspec(fn)
553
566
  if spec[3] is not None:
554
567
  positional = spec[0][1 : -len(spec[3])]
alembic/context.pyi CHANGED
@@ -151,8 +151,8 @@ def configure(
151
151
  Callable[
152
152
  [
153
153
  MigrationContext,
154
- Column,
155
- Column,
154
+ Column[Any],
155
+ Column[Any],
156
156
  Optional[str],
157
157
  Optional[FetchedValue],
158
158
  Optional[str],
alembic/ddl/base.py CHANGED
@@ -150,7 +150,7 @@ class AddColumn(AlterTable):
150
150
  def __init__(
151
151
  self,
152
152
  name: str,
153
- column: Column,
153
+ column: Column[Any],
154
154
  schema: Optional[Union[quoted_name, str]] = None,
155
155
  ) -> None:
156
156
  super().__init__(name, schema=schema)
@@ -159,7 +159,7 @@ class AddColumn(AlterTable):
159
159
 
160
160
  class DropColumn(AlterTable):
161
161
  def __init__(
162
- self, name: str, column: Column, schema: Optional[str] = None
162
+ self, name: str, column: Column[Any], schema: Optional[str] = None
163
163
  ) -> None:
164
164
  super().__init__(name, schema=schema)
165
165
  self.column = column
@@ -320,7 +320,7 @@ def alter_column(compiler: DDLCompiler, name: str) -> str:
320
320
  return "ALTER COLUMN %s" % format_column_name(compiler, name)
321
321
 
322
322
 
323
- def add_column(compiler: DDLCompiler, column: Column, **kw) -> str:
323
+ def add_column(compiler: DDLCompiler, column: Column[Any], **kw) -> str:
324
324
  text = "ADD COLUMN %s" % compiler.get_column_specification(column, **kw)
325
325
 
326
326
  const = " ".join(
alembic/ddl/impl.py CHANGED
@@ -316,7 +316,7 @@ class DefaultImpl(metaclass=ImplMeta):
316
316
  def add_column(
317
317
  self,
318
318
  table_name: str,
319
- column: Column,
319
+ column: Column[Any],
320
320
  schema: Optional[Union[str, quoted_name]] = None,
321
321
  ) -> None:
322
322
  self._exec(base.AddColumn(table_name, column, schema=schema))
@@ -324,7 +324,7 @@ class DefaultImpl(metaclass=ImplMeta):
324
324
  def drop_column(
325
325
  self,
326
326
  table_name: str,
327
- column: Column,
327
+ column: Column[Any],
328
328
  schema: Optional[str] = None,
329
329
  **kw,
330
330
  ) -> None:
@@ -379,8 +379,8 @@ class DefaultImpl(metaclass=ImplMeta):
379
379
  table, self.connection, checkfirst=False, _ddl_runner=self
380
380
  )
381
381
 
382
- def create_index(self, index: Index) -> None:
383
- self._exec(schema.CreateIndex(index))
382
+ def create_index(self, index: Index, **kw: Any) -> None:
383
+ self._exec(schema.CreateIndex(index, **kw))
384
384
 
385
385
  def create_table_comment(self, table: Table) -> None:
386
386
  self._exec(schema.SetTableComment(table))
@@ -388,11 +388,11 @@ class DefaultImpl(metaclass=ImplMeta):
388
388
  def drop_table_comment(self, table: Table) -> None:
389
389
  self._exec(schema.DropTableComment(table))
390
390
 
391
- def create_column_comment(self, column: ColumnElement) -> None:
391
+ def create_column_comment(self, column: ColumnElement[Any]) -> None:
392
392
  self._exec(schema.SetColumnComment(column))
393
393
 
394
- def drop_index(self, index: Index) -> None:
395
- self._exec(schema.DropIndex(index))
394
+ def drop_index(self, index: Index, **kw: Any) -> None:
395
+ self._exec(schema.DropIndex(index, **kw))
396
396
 
397
397
  def bulk_insert(
398
398
  self,
@@ -526,7 +526,7 @@ class DefaultImpl(metaclass=ImplMeta):
526
526
  return True
527
527
 
528
528
  def compare_type(
529
- self, inspector_column: Column, metadata_column: Column
529
+ self, inspector_column: Column[Any], metadata_column: Column
530
530
  ) -> bool:
531
531
  """Returns True if there ARE differences between the types of the two
532
532
  columns. Takes impl.type_synonyms into account between retrospected
@@ -637,7 +637,6 @@ class DefaultImpl(metaclass=ImplMeta):
637
637
  return False
638
638
 
639
639
  def _compare_identity_default(self, metadata_identity, inspector_identity):
640
-
641
640
  # ignored contains the attributes that were not considered
642
641
  # because assumed to their default values in the db.
643
642
  diff, ignored = _compare_identity_options(
@@ -669,6 +668,12 @@ class DefaultImpl(metaclass=ImplMeta):
669
668
  # order of col matters in an index
670
669
  return tuple(col.name for col in index.columns)
671
670
 
671
+ def create_unique_constraint_sig(
672
+ self, const: UniqueConstraint
673
+ ) -> Tuple[Any, ...]:
674
+ # order of col does not matters in an unique constraint
675
+ return tuple(sorted([col.name for col in const.columns]))
676
+
672
677
  def _skip_functional_indexes(self, metadata_indexes, conn_indexes):
673
678
  conn_indexes_by_name = {c.name: c for c in conn_indexes}
674
679