Skip to content

Commit b893289

Browse files
authored
Complete Flask-Migrate and mark as Strict (#10971)
1 parent d9311f9 commit b893289

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

pyrightconfig.stricter.json

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"stubs/commonmark",
3636
"stubs/dateparser",
3737
"stubs/docutils",
38-
"stubs/Flask-Migrate",
3938
"stubs/Flask-SocketIO",
4039
"stubs/fpdf2",
4140
"stubs/google-cloud-ndb",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Flask-Migrate users don't need to interact with this undocumented module from within python
2+
flask_migrate.cli

stubs/Flask-Migrate/METADATA.toml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
version = "4.0.*"
2-
upstream_repository = "https://github.com/miguelgrinberg/flask-migrate"
2+
upstream_repository = "https://github.com/miguelgrinberg/Flask-Migrate"
33
# Requires versions of flask and Flask-SQLAlchemy with `py.typed` files
4-
requires = ["Flask>=2.0.0", "Flask-SQLAlchemy>=3.0.1"]
5-
partial_stub = true
6-
7-
[tool.stubtest]
8-
ignore_missing_stub = true
4+
requires = ["Flask-SQLAlchemy>=3.0.1", "Flask>=2.0.0"]

stubs/Flask-Migrate/flask_migrate/__init__.pyi

+35-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
1+
# pyright: reportInvalidStubStatement=none
2+
3+
import sys
4+
from _typeshed import StrPath, SupportsKeysAndGetItem, SupportsWrite
5+
from argparse import Namespace
16
from collections.abc import Callable, Iterable, Sequence
27
from logging import Logger
3-
from typing import Any, TypeVar
8+
from typing import Any, Protocol, TypeVar
49
from typing_extensions import ParamSpec, TypeAlias
510

611
import flask
712
from flask_sqlalchemy import SQLAlchemy
813

914
_T = TypeVar("_T")
15+
_T_contra = TypeVar("_T_contra", contravariant=True)
1016
_P = ParamSpec("_P")
1117
_ConfigureCallback: TypeAlias = Callable[[Config], Config]
18+
_AlembicConfigValue: TypeAlias = Any
1219

1320
alembic_version: tuple[int, int, int]
1421
log: Logger
1522

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+
1627
class Config: # should inherit from alembic.config.Config which is not possible yet
1728
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: ...
1946
def get_template_directory(self) -> str: ...
2047

2148
class Migrate:
2249
configure_callbacks: list[_ConfigureCallback]
2350
db: SQLAlchemy | None
2451
directory: str
25-
alembic_ctx_kwargs: dict[str, Any]
52+
alembic_ctx_kwargs: dict[str, _AlembicConfigValue]
2653
def __init__(
2754
self,
2855
app: flask.Flask | None = None,
@@ -31,7 +58,7 @@ class Migrate:
3158
command: str = "db",
3259
compare_type: bool = True,
3360
render_as_batch: bool = True,
34-
**kwargs,
61+
**kwargs: _AlembicConfigValue,
3562
) -> None: ...
3663
def init_app(
3764
self,
@@ -41,13 +68,13 @@ class Migrate:
4168
command: str | None = None,
4269
compare_type: bool | None = None,
4370
render_as_batch: bool | None = None,
44-
**kwargs,
71+
**kwargs: _AlembicConfigValue,
4572
) -> None: ...
4673
def configure(self, f: _ConfigureCallback) -> _ConfigureCallback: ...
47-
def call_configure_callbacks(self, config: Config): ...
74+
def call_configure_callbacks(self, config: Config) -> Config: ...
4875
def get_config(
4976
self, directory: str | None = None, x_arg: str | Sequence[str] | None = None, opts: Iterable[str] | None = None
50-
): ...
77+
) -> Config: ...
5178

5279
def catch_errors(f: Callable[_P, _T]) -> Callable[_P, _T]: ...
5380
def list_templates() -> None: ...
@@ -104,3 +131,4 @@ def heads(directory: str | None = None, verbose: bool = False, resolve_dependenc
104131
def branches(directory: str | None = None, verbose: bool = False) -> None: ...
105132
def current(directory: str | None = None, verbose: bool = False) -> None: ...
106133
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

Comments
 (0)