88from argparse import Namespace
99from tempfile import TemporaryDirectory
1010from configparser import DuplicateSectionError
11- from typing_extensions import ParamSpec , Concatenate
11+ from typing import Any , Set , Tuple , TextIO , cast
1212from contextlib import ExitStack , suppress , contextmanager
1313from collections .abc import Mapping , Iterable , Sequence , Generator
14- from typing import Any , Set , Tuple , TextIO , TypeVar , Callable , cast
1514
1615import click
1716from nonebot import logger
@@ -427,16 +426,16 @@ def revision(
427426 if sql :
428427
429428 def retrieve_migrations (
430- rev : tuple [ str , ...] , context : MigrationContext
431- ) -> tuple [() ]:
429+ rev , context : MigrationContext
430+ ) -> Iterable [ StampStep | RevisionStep ]:
432431 revision_context .run_no_autogenerate (rev , context )
433432 return ()
434433
435434 else :
436435
437436 def retrieve_migrations (
438- rev : tuple [ str , ...] , context : MigrationContext
439- ) -> tuple [() ]:
437+ rev , context : MigrationContext
438+ ) -> Iterable [ StampStep | RevisionStep ]:
440439 if set (script .get_revisions (rev )) != set (script .get_revisions ("heads" )):
441440 raise click .UsageError ("目标数据库未更新到最新迁移. 请通过 `nb orm upgrade` 升级数据库后重试." )
442441 revision_context .run_autogenerate (rev , context )
@@ -482,8 +481,8 @@ def check(config: AlembicConfig) -> None:
482481 )
483482
484483 def retrieve_migrations (
485- rev : tuple [ str , ...] , context : MigrationContext
486- ) -> tuple [() ]:
484+ rev , context : MigrationContext
485+ ) -> Iterable [ StampStep | RevisionStep ]:
487486 if set (script .get_revisions (rev )) != set (script .get_revisions ("heads" )):
488487 raise click .UsageError ("目标数据库未更新到最新迁移. 请通过 `nb orm upgrade` 升级数据库后重试." )
489488 revision_context .run_autogenerate (rev , context )
@@ -526,7 +525,7 @@ def merge(
526525 """
527526
528527 script = ScriptDirectory .from_config (config )
529- template_args = {"config" : config }
528+ template_args : dict [ str , Any ] = {"config" : config }
530529
531530 environment = asbool (config .get_main_option ("revision_environment" ))
532531
@@ -544,9 +543,9 @@ def merge(
544543 rev_id or _rev_id (),
545544 message ,
546545 refresh = True ,
547- head = revisions , # type: ignore[arg-type]
546+ head = revisions ,
548547 branch_labels = branch_label ,
549- ** template_args , # type: ignore[arg-type]
548+ ** template_args ,
550549 )
551550 return (sc ,) if sc else ()
552551
@@ -578,8 +577,8 @@ def upgrade(
578577 starting_rev , revision = revision .split (":" , 2 )
579578
580579 @return_progressbar
581- def upgrade (rev : tuple [ str , ...], _ ) -> list [ RevisionStep ]:
582- return script ._upgrade_revs (revision , rev ) # type: ignore
580+ def upgrade (rev , _ ) -> Iterable [ StampStep | RevisionStep ]:
581+ yield from script ._upgrade_revs (revision , rev )
583582
584583 with EnvironmentContext (
585584 config ,
@@ -620,8 +619,8 @@ def downgrade(
620619 )
621620
622621 @return_progressbar
623- def downgrade (rev : tuple [ str , ...], _ ) -> list [ RevisionStep ]:
624- return script ._downgrade_revs (revision , rev ) # type: ignore
622+ def downgrade (rev , _ ) -> Iterable [ StampStep | RevisionStep ]:
623+ yield from script ._downgrade_revs (revision , rev )
625624
626625 with EnvironmentContext (
627626 config ,
@@ -662,8 +661,8 @@ def sync(config: AlembicConfig, revision: str | None = None):
662661 )
663662
664663 def retrieve_migrations (
665- _ , context : MigrationContext
666- ) -> list [ RevisionStep ] | tuple [() ]:
664+ rev , context : MigrationContext
665+ ) -> Iterable [ StampStep | RevisionStep ]:
667666 assert context .connection
668667
669668 if not (revision or compare_metadata (context , context .opts ["target_metadata" ])):
@@ -841,7 +840,9 @@ def current(config: AlembicConfig, verbose: bool = False) -> None:
841840
842841 script = ScriptDirectory .from_config (config )
843842
844- def display_version (rev : tuple [str , ...], context : MigrationContext ) -> tuple [()]:
843+ def display_version (
844+ rev , context : MigrationContext
845+ ) -> Iterable [StampStep | RevisionStep ]:
845846 if verbose :
846847 config .print_stdout (
847848 "Current revision(s) for %s:" ,
@@ -894,8 +895,9 @@ def stamp(
894895 else :
895896 destination_revs = revisions
896897
897- def do_stamp (rev : tuple [str , ...], _ ) -> list [StampStep ]:
898- return script ._stamp_revs (destination_revs , rev )
898+ def do_stamp (rev , _ ) -> Iterable [StampStep | RevisionStep ]:
899+ yield from script ._stamp_revs (destination_revs , rev )
900+ _move_run_scripts (config , script , destination_revs )
899901
900902 with EnvironmentContext (
901903 config ,
@@ -922,7 +924,7 @@ def edit(config: AlembicConfig, rev: str = "current") -> None:
922924
923925 if rev == "current" :
924926
925- def edit_current (rev : tuple [ str , ...], _ ) -> tuple [() ]:
927+ def edit_current (rev , _ ) -> Iterable [ StampStep | RevisionStep ]:
926928 if not rev :
927929 raise click .UsageError ("当前没有迁移" )
928930
@@ -955,7 +957,9 @@ def ensure_version(config: AlembicConfig, sql: bool = False) -> None:
955957
956958 script = ScriptDirectory .from_config (config )
957959
958- def do_ensure_version (_ , context : MigrationContext ) -> tuple [()]:
960+ def do_ensure_version (
961+ _ , context : MigrationContext
962+ ) -> Iterable [StampStep | RevisionStep ]:
959963 context ._ensure_version_table ()
960964 return ()
961965
0 commit comments