1
+ # pyright: reportInvalidStubStatement=none
2
+
3
+ import sys
4
+ from _typeshed import StrPath , SupportsKeysAndGetItem , SupportsWrite
5
+ from argparse import Namespace
1
6
from collections .abc import Callable , Iterable , Sequence
2
7
from logging import Logger
3
- from typing import Any , TypeVar
8
+ from typing import Any , Protocol , TypeVar
4
9
from typing_extensions import ParamSpec , TypeAlias
5
10
6
11
import flask
7
12
from flask_sqlalchemy import SQLAlchemy
8
13
9
14
_T = TypeVar ("_T" )
15
+ _T_contra = TypeVar ("_T_contra" , contravariant = True )
10
16
_P = ParamSpec ("_P" )
11
17
_ConfigureCallback : TypeAlias = Callable [[Config ], Config ]
18
+ _AlembicConfigValue : TypeAlias = Any
12
19
13
20
alembic_version : tuple [int , int , int ]
14
21
log : Logger
15
22
23
+ # TODO: Use _typeshed.SupportsFlush when it's available in type checkers.
24
+ class _SupportsWriteAndFlush (SupportsWrite [_T_contra ], Protocol ):
25
+ def flush (self ) -> object : ...
26
+
16
27
class Config : # should inherit from alembic.config.Config which is not possible yet
17
28
template_directory : str | None
18
- def __init__ (self , * args , ** kwargs ) -> None : ...
29
+ # Same as alembic.config.Config + template_directory kwarg
30
+ def __init__ (
31
+ self ,
32
+ file_ : StrPath | None = None ,
33
+ ini_section : str = "alembic" ,
34
+ # Same as buffer argument in TextIOWrapper.__init__.buffer
35
+ output_buffer : _SupportsWriteAndFlush [str ] | None = None ,
36
+ # Same as stream argument in alembic.util.messaging
37
+ stdout : SupportsWrite [str ] = sys .stdout ,
38
+ cmd_opts : Namespace | None = None ,
39
+ config_args : SupportsKeysAndGetItem [str , _AlembicConfigValue ] | Iterable [tuple [str , _AlembicConfigValue ]] = ...,
40
+ attributes : SupportsKeysAndGetItem [_AlembicConfigValue , _AlembicConfigValue ]
41
+ | Iterable [tuple [_AlembicConfigValue , _AlembicConfigValue ]]
42
+ | None = None ,
43
+ * ,
44
+ template_directory : str | None = None ,
45
+ ) -> None : ...
19
46
def get_template_directory (self ) -> str : ...
20
47
21
48
class Migrate :
22
49
configure_callbacks : list [_ConfigureCallback ]
23
50
db : SQLAlchemy | None
24
51
directory : str
25
- alembic_ctx_kwargs : dict [str , Any ]
52
+ alembic_ctx_kwargs : dict [str , _AlembicConfigValue ]
26
53
def __init__ (
27
54
self ,
28
55
app : flask .Flask | None = None ,
@@ -31,7 +58,7 @@ class Migrate:
31
58
command : str = "db" ,
32
59
compare_type : bool = True ,
33
60
render_as_batch : bool = True ,
34
- ** kwargs ,
61
+ ** kwargs : _AlembicConfigValue ,
35
62
) -> None : ...
36
63
def init_app (
37
64
self ,
@@ -41,13 +68,13 @@ class Migrate:
41
68
command : str | None = None ,
42
69
compare_type : bool | None = None ,
43
70
render_as_batch : bool | None = None ,
44
- ** kwargs ,
71
+ ** kwargs : _AlembicConfigValue ,
45
72
) -> None : ...
46
73
def configure (self , f : _ConfigureCallback ) -> _ConfigureCallback : ...
47
- def call_configure_callbacks (self , config : Config ): ...
74
+ def call_configure_callbacks (self , config : Config ) -> Config : ...
48
75
def get_config (
49
76
self , directory : str | None = None , x_arg : str | Sequence [str ] | None = None , opts : Iterable [str ] | None = None
50
- ): ...
77
+ ) -> Config : ...
51
78
52
79
def catch_errors (f : Callable [_P , _T ]) -> Callable [_P , _T ]: ...
53
80
def list_templates () -> None : ...
@@ -104,3 +131,4 @@ def heads(directory: str | None = None, verbose: bool = False, resolve_dependenc
104
131
def branches (directory : str | None = None , verbose : bool = False ) -> None : ...
105
132
def current (directory : str | None = None , verbose : bool = False ) -> None : ...
106
133
def stamp (directory : str | None = None , revision : str = "head" , sql : bool = False , tag : str | None = None ) -> None : ...
134
+ def check (directory : str | None = None ) -> None : ...
0 commit comments