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

AsyncEngine._trans_ctx typed as returning self on aenter rather than AsyncConn #109

Closed
FasterSpeeding opened this issue May 17, 2021 · 1 comment
Labels
bug Something isn't working mypy

Comments

@FasterSpeeding
Copy link
Contributor

FasterSpeeding commented May 17, 2021

Describe the bug
AsyncEngine._trans_ctx is typed as returning itself on __aenter__.

Expected behavior
AsyncEngine._trans_ctx should be typed as returning AsyncConnection on __aenter__.

To Reproduce
Please try to provide a Minimal, Complete, and Verifiable example.
See also Reporting Bugs on the website, and some example issues.

Please do not use Flask-SQLAlchemy or any other third-party extensions or dependencies in test cases. The test case must illustrate the problem without using any third party SQLAlchemy extensions. Otherwise, please report the bug to those projects first.

from sqlalchemy.ext import asyncio


async def test() -> None:
    database = asyncio.create_async_engine("", future=True)

    trans_ctx = database.begin()
    reveal_type(trans_ctx)
    async with trans_ctx as connection:
        await connection.execute(...)

Error

PS C:\Users\Lucina\PycharmProjects\PTF> mypy test1.py
test1.py: note: In function "test":
test1.py:8:17: note: Revealed type is 'sqlalchemy.ext.asyncio.engine.AsyncEngine._trans_ctx'
test1.py:10:15: error: "_trans_ctx" has no attribute "execute"  [attr-defined]
            await connection.execute(...)
                  ^
Found 1 error in 1 file (checked 1 source file)

Versions.

  • OS: Windows 10
  • Python: 3.9.4
  • SQLAlchemy: 1.4.14
  • mypy: 0.812
  • SQLAlchemy2-stubs: 0.0.2a1

Additional context
This feels similar to #93 except that issue seems to focus on the return type of AsyncEngine.begin() without actually raising the fact that the typed behaviour of AsyncEngine._trans_ctx is erroneous.

Have a nice day!

@FasterSpeeding FasterSpeeding added the requires triage New issue that requires categorization label May 17, 2021
@CaselIT CaselIT added bug Something isn't working mypy and removed requires triage New issue that requires categorization labels Jun 7, 2021
MaicoTimmerman added a commit to MaicoTimmerman/sqlalchemy2-stubs that referenced this issue Jun 25, 2021
MaicoTimmerman added a commit that referenced this issue Jun 25, 2021
* Fix return typing of AsyncEngine._trans_ctx.__aenter__
* StartableContext is made generic as to remove the assumption that it'll always be returning itself which is not the case for for it's behaviour in _trans_ctx

* tests: add testcase for #109

Co-authored-by: Faster Speeding <luke@lmbyrne.dev>
@CaselIT
Copy link
Member

CaselIT commented Jul 30, 2021

this was fixed

@CaselIT CaselIT closed this as completed Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mypy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants