Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing type stubs #1378

Closed
stinovlas opened this issue Dec 19, 2023 · 5 comments
Closed

Missing type stubs #1378

stinovlas opened this issue Dec 19, 2023 · 5 comments

Comments

@stinovlas
Copy link

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
@stinovlas stinovlas added the requires triage New issue that requires categorization label Dec 19, 2023
@CaselIT CaselIT added expected behavior and removed requires triage New issue that requires categorization labels Dec 19, 2023
@CaselIT
Copy link
Member

CaselIT commented Dec 19, 2023

Hi,

Alembic has no sync_enum_values function, so it would be strange to expose it in the types

@CaselIT CaselIT closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@stinovlas
Copy link
Author

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?

@CaselIT
Copy link
Member

CaselIT commented Dec 19, 2023

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(...)

@zzzeek
Copy link
Member

zzzeek commented Dec 19, 2023

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.

@stinovlas
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants