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

Pyright in "strict" mode complains about "begin_transaction" #1201

Closed
AlexanderPodorov opened this issue Mar 9, 2023 · 6 comments
Closed
Labels
bug Something isn't working pep 484 typing related issues PRs (with tests!) welcome

Comments

@AlexanderPodorov
Copy link

When env.py is generated, this line is usually added:

from alembic.context import begin_transaction

VSCode (pylance/pyright) compains about it saying:
Type of "begin_transaction" is partially unknown
Most likely because of:

def begin_transaction() -> Union[_ProxyTransaction, ContextManager]:

where the type of ContextManager generic is not specified

Expected behavior
No warnings

Versions.

  • OS: MacOS
  • Python: 3.11.2
  • Alembic: 1.10.1
  • SQLAlchemy: 2.0.5.post1
  • Database: Postgres 15
  • DBAPI: asyncpg

Have a nice day!

@AlexanderPodorov AlexanderPodorov added the requires triage New issue that requires categorization label Mar 9, 2023
@zzzeek zzzeek added bug Something isn't working pep 484 typing related issues PRs (with tests!) welcome and removed requires triage New issue that requires categorization labels Mar 9, 2023
@zzzeek
Copy link
Member

zzzeek commented Mar 9, 2023

thanks for reporting

cc @CaselIT

@CaselIT
Copy link
Member

CaselIT commented Mar 9, 2023

Thanks for reporting.

@CaselIT
Copy link
Member

CaselIT commented Mar 9, 2023

Please note that both alembic and sqlalchemy are currently "best effort" type checking with pyright/pylance. A lot of similar issues will came up running them, especially in strict mode

@sqla-tester
Copy link
Collaborator

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

Correctly account for generic in Function https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4492

@AlexanderPodorov
Copy link
Author

Thanks for the note, that's fine. sqlalchemy and alembic are doing the great job of implementing proper type hinting!
I personally have not seen a lot of typing issues yet. Refining existing type hints is also great.
I would mention this particular issue is not related to pyright/pylance, mypy in strict mode will likely show a warning either (however I did not test that). I believe the respective setting for that is --disallow-any-generics. Thanks!

@CaselIT
Copy link
Member

CaselIT commented Mar 9, 2023

BTW I did not want to discourage future issues on this, just stating the current status of alembic and sqlalchemy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pep 484 typing related issues PRs (with tests!) welcome
Projects
None yet
Development

No branches or pull requests

4 participants