Missing type stubs
stinovlas opened this issue · comments
Describe the bug
Function sync_enum_values
is missing from alembic/op.pyi
type stubs file. It's possible that there are some other function annotations missing as well. It's hard to check since alembic/op.py
is dynamic.
Expected behavior
Function sync_enum_values
should be annotated.
To Reproduce
from alembic import op
def upgrade() -> None:
op.sync_enum_values(
"public",
"taskstatus",
[
"NEW",
"PENDING",
"STOPPED",
],
[("task", "status")],
enum_values_to_rename=[],
)
Call mypy alembic_example.py
.
Error
alembic_test.py:4: error: Module has no attribute "sync_enum_values" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Versions.
- OS: Linux
- Python: 3.11.6
- Alembic: 1.13.0
- SQLAlchemy: 2.0.22
- Database: does not apply
- DBAPI: does not apply
Hi,
Alembic has no sync_enum_values
function, so it would be strange to expose it in the types
Hi,
Alembic has no
sync_enum_values
function, so it would be strange to expose it in the types
Sorry about that, it seems that it originates from alembic-postgresql-enum. Still, it's somehow injected to alembic.op
. Is there any standard way to type hint alembic plugins?
I don't think it's something that's supported by python, but I may be mistaken here.
maybe that plugin could export a module that copies over what it adds to op
so that you could do something like
from alembic_postgresql_enum import ape_op
...
ape_op.sync_enum_values(...)
the dynamic nature of the "op" module precedes Python pep-484 typing. given today's reality, we probably would not have used this model.
I would suggest that third party libraries that have their own Alembic symbols provide a direct module-access space of their own from which to call upon these functions.
It seems that the plugin uses @alembic.operations.base.Operations.register_operation("sync_enum_values")
decorator. That's hard to resolve because mypy
only does static type checking. I guess it could be solved by mypy plugin, but that's a lot more work. Thank you both for your comments, it has been helpful for me to understand the underlying problem.