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

[mypy] error: Argument 1 to "execute" has incompatible type "Delete"; expected "Union[str, TextClause, Update]" #1058

Closed
arjenzorgdoc opened this issue Jun 30, 2022 · 5 comments
Labels
bug Something isn't working op directives pep 484 typing related issues

Comments

@arjenzorgdoc
Copy link

Describe the bug
mypy doesn't allow Delete() as parameter to op.execute().

Expected behavior
no mypy error?

To Reproduce

from alembic import op
from sqlalchemy import table            
op.execute(table("test").delete())

Error

test.py:3: error: Argument 1 to "execute" has incompatible type "Delete"; expected "Union[str, TextClause, Update]"

Versions.

  • OS: linux
  • Python: 3.8
  • Alembic: 1.8.0
  • SQLAlchemy: 1.3.18
  • Database: n/a
  • DBAPI: n/a

Have a nice day!
Thanks!

@arjenzorgdoc arjenzorgdoc added the requires triage New issue that requires categorization label Jun 30, 2022
@arjenzorgdoc
Copy link
Author

Maybe in ddl/impl.py:

     def execute(
         self,
-        sql: Union["Update", "TextClause", str],
+        sql: Union["UpdateBase", "TextClause", str],
         execution_options: None = None,
     ) -> None:
         self._exec(sql, execution_options)

@zzzeek zzzeek added bug Something isn't working op directives mypy and removed requires triage New issue that requires categorization labels Jun 30, 2022
@zzzeek
Copy link
Member

zzzeek commented Jun 30, 2022

agree, "Update" seems kind of arbitrary. I would think Executable is the safer choice

cc @CaselIT

@CaselIT
Copy link
Member

CaselIT commented Jun 30, 2022

That type probably was the one auto-generated from the tests. We can do executable|str

@zzzeek zzzeek added pep 484 typing related issues and removed mypy labels Jul 7, 2022
@CaselIT
Copy link
Member

CaselIT commented Aug 31, 2023

This is actually the same as #1277

@sqla-tester
Copy link
Collaborator

Mihail Milushev has proposed a fix for this issue in the main branch:

Improve typing of op.execute https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4835

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working op directives pep 484 typing related issues
Projects
None yet
Development

No branches or pull requests

4 participants