Minor fixes for compatibility with Pylance
public
Minor fixes for compatibility with Pylance
modified
src/mitch/cli/deploy.py
+3 −2
| @@ -37,7 +37,8 @@ |
| 37 | 37 | # Resolve database URL |
| 38 | 38 | resolved_database_url = database_url or os.getenv("MITCH_DATABASE_URL") or os.getenv("DATABASE_URL") |
| 39 | 39 | if not resolved_database_url: |
| 40 | | - raise typer.Exit(1, "Database URL must be provided via --database option or MITCH_DATABASE_URL/DATABASE_URL environment variable.") |
| 40 | + typer.echo("Error: Database URL must be provided via --database option or MITCH_DATABASE_URL/DATABASE_URL environment variable.", err=True) |
| 41 | + raise typer.Exit(1) |
| 41 | 42 | engine = sa.create_engine(resolved_database_url) |
| 42 | 43 | |
| 43 | 44 | # Fetch due migrations |
| @@ -88,7 +89,7 @@ |
| 88 | 89 | |
| 89 | 90 | # Prepare to redeploy modified migrations, together with the |
| 90 | 91 | if migrations_to_revert: |
| 91 | | - due_ids = set(migration_ids) + set(m.id for m in migrations_to_revert) |
| 92 | + due_ids = set(migration_ids) | {m.id for m in migrations_to_revert} |
| 92 | 93 | due_migrations = list(repo.by_ids_with_dependencies(*due_ids)) |
| 93 | 94 | |
| 94 | 95 | # Deploy due and reverted migrations |
modified
src/mitch/helpers.py
+5 −3
| @@ -1,11 +1,13 @@ |
| 1 | 1 | from itertools import groupby, count |
| 2 | | -from collections import namedtuple |
| 2 | +from typing import NamedTuple, Iterable |
| 3 | 3 | |
| 4 | 4 | from .migration import Migration |
| 5 | 5 | |
| 6 | | -Batch = namedtuple('Batch', ['transactional', 'migrations']) |
| 6 | +class Batch(NamedTuple): |
| 7 | + transactional: bool |
| 8 | + migrations: Iterable[Migration] |
| 7 | 9 | |
| 8 | | -def batch_transactional_migrations(migrations: iter[Migration]) -> iter[iter[Migration]]: |
| 10 | +def batch_transactional_migrations(migrations: Iterable[Migration]) -> Iterable[Batch]: |
| 9 | 11 | """Splits a list of migrations into batches based on their transactional property. |
| 10 | 12 | |
| 11 | 13 | Each batch is a list of migrations that can be run together in a single transaction. |
modified
src/mitch/repository.py
+6 −5
| @@ -2,6 +2,7 @@ |
| 2 | 2 | from pathlib import Path |
| 3 | 3 | from graphlib import TopologicalSorter |
| 4 | 4 | from weakref import WeakValueDictionary |
| 5 | +from typing import Iterable |
| 5 | 6 | import tomllib |
| 6 | 7 | |
| 7 | 8 | from .migration import Migration |
| @@ -18,7 +19,7 @@ |
| 18 | 19 | return tomllib.load(f) |
| 19 | 20 | return {} |
| 20 | 21 | |
| 21 | | - def _load_migrations(self) -> iter[Migration]: |
| 22 | + def _load_migrations(self): |
| 22 | 23 | # Fetch migrations |
| 23 | 24 | self.migrations = [] |
| 24 | 25 | for up_script in self.path.rglob("*.up.sql"): |
| @@ -53,7 +54,7 @@ |
| 53 | 54 | dependency.dependants.add(migration.id) |
| 54 | 55 | |
| 55 | 56 | |
| 56 | | - def _iter_sorter(self, sorter: TopologicalSorter) -> iter[Migration]: |
| 57 | + def _iter_sorter(self, sorter: TopologicalSorter) -> Iterable[Migration]: |
| 57 | 58 | sorter.prepare() |
| 58 | 59 | while sorter.is_active(): |
| 59 | 60 | level = (self.by_id(id_) for id_ in sorter.get_ready()) |
| @@ -67,14 +68,14 @@ |
| 67 | 68 | except KeyError: |
| 68 | 69 | raise MissingMigrationError(migration_id) |
| 69 | 70 | |
| 70 | | - def by_ids(self, *migration_id: str) -> iter[Migration]: |
| 71 | + def by_ids(self, *migration_id: str) -> Iterable[Migration]: |
| 71 | 72 | for id_ in migration_id: |
| 72 | 73 | yield self.by_id(id_) |
| 73 | 74 | |
| 74 | | - def by_ids_with_dependencies(self, *migration_id: str) -> iter[Migration]: |
| 75 | + def by_ids_with_dependencies(self, *migration_id: str) -> Iterable[Migration]: |
| 75 | 76 | sorter = TopologicalSorter({ m.id: m.dependencies for m in self.by_ids(*migration_id) }) |
| 76 | 77 | yield from self._iter_sorter(sorter) |
| 77 | 78 | |
| 78 | | - def by_ids_with_dependants(self, *migration_id: str) -> iter[Migration]: |
| 79 | + def by_ids_with_dependants(self, *migration_id: str) -> Iterable[Migration]: |
| 79 | 80 | sorter = TopologicalSorter({ m.id: m.dependants for m in self.by_ids(*migration_id) }) |
| 80 | 81 | yield from self._iter_sorter(sorter) |