Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"stubs/commonmark",
"stubs/dateparser",
"stubs/docutils",
"stubs/Flask-Migrate",
"stubs/Flask-SocketIO",
"stubs/fpdf2",
"stubs/google-cloud-ndb",
Expand Down
2 changes: 2 additions & 0 deletions stubs/Flask-Migrate/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Flask-Migrate users don't need to interact with this undocumented module from within python
flask_migrate.cli
8 changes: 2 additions & 6 deletions stubs/Flask-Migrate/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
version = "4.0.*"
upstream_repository = "https://github.com/miguelgrinberg/flask-migrate"
upstream_repository = "https://github.com/miguelgrinberg/Flask-Migrate"
# Requires versions of flask and Flask-SQLAlchemy with `py.typed` files
requires = ["Flask>=2.0.0", "Flask-SQLAlchemy>=3.0.1"]
partial_stub = true

[tool.stubtest]
ignore_missing_stub = true
requires = ["Flask-SQLAlchemy>=3.0.1", "Flask>=2.0.0"]
42 changes: 35 additions & 7 deletions stubs/Flask-Migrate/flask_migrate/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
# pyright: reportInvalidStubStatement=none

import sys
from _typeshed import StrPath, SupportsKeysAndGetItem, SupportsWrite
from argparse import Namespace
from collections.abc import Callable, Iterable, Sequence
from logging import Logger
from typing import Any, TypeVar
from typing import Any, Protocol, TypeVar
from typing_extensions import ParamSpec, TypeAlias

import flask
from flask_sqlalchemy import SQLAlchemy

_T = TypeVar("_T")
_T_contra = TypeVar("_T_contra", contravariant=True)
_P = ParamSpec("_P")
_ConfigureCallback: TypeAlias = Callable[[Config], Config]
_AlembicConfigValue: TypeAlias = Any

alembic_version: tuple[int, int, int]
log: Logger

# TODO: Use _typeshed.SupportsFlush when it's available in type checkers.
class _SupportsWriteAndFlush(SupportsWrite[_T_contra], Protocol):
def flush(self) -> object: ...

class Config: # should inherit from alembic.config.Config which is not possible yet
template_directory: str | None
def __init__(self, *args, **kwargs) -> None: ...
# Same as alembic.config.Config + template_directory kwarg
def __init__(
self,
file_: StrPath | None = None,
ini_section: str = "alembic",
# Same as buffer argument in TextIOWrapper.__init__.buffer
output_buffer: _SupportsWriteAndFlush[str] | None = None,
# Same as stream argument in alembic.util.messaging
stdout: SupportsWrite[str] = sys.stdout,
cmd_opts: Namespace | None = None,
config_args: SupportsKeysAndGetItem[str, _AlembicConfigValue] | Iterable[tuple[str, _AlembicConfigValue]] = ...,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config_args and attributes are used to create and update a dict respectively. I don't remember if it's better to type this as a Mapping like alembic did for config_args or maybe make a ConvertibleToDict type like in #10707

attributes: SupportsKeysAndGetItem[_AlembicConfigValue, _AlembicConfigValue]
| Iterable[tuple[_AlembicConfigValue, _AlembicConfigValue]]
| None = None,
*,
template_directory: str | None = None,
) -> None: ...
def get_template_directory(self) -> str: ...

class Migrate:
configure_callbacks: list[_ConfigureCallback]
db: SQLAlchemy | None
directory: str
alembic_ctx_kwargs: dict[str, Any]
alembic_ctx_kwargs: dict[str, _AlembicConfigValue]
def __init__(
self,
app: flask.Flask | None = None,
Expand All @@ -31,7 +58,7 @@ class Migrate:
command: str = "db",
compare_type: bool = True,
render_as_batch: bool = True,
**kwargs,
**kwargs: _AlembicConfigValue,
) -> None: ...
def init_app(
self,
Expand All @@ -41,13 +68,13 @@ class Migrate:
command: str | None = None,
compare_type: bool | None = None,
render_as_batch: bool | None = None,
**kwargs,
**kwargs: _AlembicConfigValue,
) -> None: ...
def configure(self, f: _ConfigureCallback) -> _ConfigureCallback: ...
def call_configure_callbacks(self, config: Config): ...
def call_configure_callbacks(self, config: Config) -> Config: ...
def get_config(
self, directory: str | None = None, x_arg: str | Sequence[str] | None = None, opts: Iterable[str] | None = None
): ...
) -> Config: ...

def catch_errors(f: Callable[_P, _T]) -> Callable[_P, _T]: ...
def list_templates() -> None: ...
Expand Down Expand Up @@ -104,3 +131,4 @@ def heads(directory: str | None = None, verbose: bool = False, resolve_dependenc
def branches(directory: str | None = None, verbose: bool = False) -> None: ...
def current(directory: str | None = None, verbose: bool = False) -> None: ...
def stamp(directory: str | None = None, revision: str = "head", sql: bool = False, tag: str | None = None) -> None: ...
def check(directory: str | None = None) -> None: ...