sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.84k stars 247 forks source link

Missing typing support for string collections in some commands #930

Closed QuicksilverMachine closed 1 year ago

QuicksilverMachine commented 3 years ago

Describe the bug

Typing of a couple of parameters is wrong. They are set to be str or Optional[str] only, when they can accept lists or tuples. Specifically it's the following functions:

alembic.command.revision - depends_on parameter alembic.command.stamp - revisions parameter alembic.command.merge - revisions parameter

Expected behavior

The typing should reflect the implementation.

To Reproduce Simply run mypy with parameters being a tuple or list of strings.

Error

************.py: note: In function "merge":
************.py:165: error: Argument "revisions" to "merge" has incompatible type "List[str]"; expected "str"  [arg-type]
            config, revisions=revisions, message=message, branch_label=branch_label
                              ^
************.py: note: In function "revision":
************.py:262: error: Argument "depends_on" to "revision" has incompatible type "Tuple[str]"; expected "Optional[str]"  [arg-type]
            depends_on=depends_on,
                       ^
************.py: note: In function "stamp":
************.py:302: error: Argument "revision" to "stamp" has incompatible type "Tuple[str]"; expected "str"  [arg-type]

Versions.

Additional context None

Have a nice day!

CaselIT commented 3 years ago

Thanks for reporing. PRs are welcome

sqla-tester commented 1 year ago

Federico Caselli has proposed a fix for this issue in the main branch:

Improve typings https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4836