From 2b7a4aa9cf60d55508a10ceee2f4a0bd136100bb Mon Sep 17 00:00:00 2001 From: Ruslan Ilyasovich Gilfanov Date: Sun, 15 Sep 2024 09:41:20 +0500 Subject: [PATCH] Release 1.0.0 * Added support for SQLAlchemy 2.0 * Dropped support for SQLAlchemy 1.4 --- README.rst | 2 +- docs/index.rst | 2 +- docs/quickstart.rst | 2 +- docs/releases.rst | 14 +- examples/test_example.py | 20 +-- poetry.lock | 154 ++++++++++-------- pyproject.toml | 20 +-- .../aiohttp_sqlalchemy}/__init__.py | 4 +- .../aiohttp_sqlalchemy}/constants.py | 0 .../aiohttp_sqlalchemy}/decorators.py | 6 +- .../aiohttp_sqlalchemy}/exceptions.py | 0 .../aiohttp_sqlalchemy}/middlewares.py | 0 .../aiohttp_sqlalchemy}/py.typed | 0 .../aiohttp_sqlalchemy}/typedefs.py | 6 +- .../aiohttp_sqlalchemy}/utils.py | 13 +- .../aiohttp_sqlalchemy}/web_handlers.py | 4 +- tests/conftest.py | 31 ++-- tests/test_aiohttp_sqlalchemy.py | 2 + tests/test_bind.py | 12 +- tests/test_constants.py | 2 + tests/test_decorators.py | 11 +- tests/test_middlewares.py | 11 +- tests/test_setup.py | 11 +- tests/test_utils.py | 12 +- tests/test_web_handlers.py | 22 ++- 25 files changed, 206 insertions(+), 155 deletions(-) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/__init__.py (96%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/constants.py (100%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/decorators.py (89%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/exceptions.py (100%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/middlewares.py (100%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/py.typed (100%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/typedefs.py (63%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/utils.py (86%) rename {aiohttp_sqlalchemy => src/aiohttp_sqlalchemy}/web_handlers.py (97%) diff --git a/README.rst b/README.rst index af59e6d..aef7d15 100644 --- a/README.rst +++ b/README.rst @@ -35,7 +35,7 @@ aiohttp-sqlalchemy :target: https://www.codacy.com/gh/ri-gilfanov/aiohttp-sqlalchemy/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ri-gilfanov/aiohttp-sqlalchemy&utm_campaign=Badge_Grade :alt: Codacy code quality -`SQLAlchemy 1.4 / 2.0 `_ support for `AIOHTTP +`SQLAlchemy 2.0 `_ support for `AIOHTTP `_. The library provides the next features: diff --git a/docs/index.rst b/docs/index.rst index 9623a31..361c02b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -35,7 +35,7 @@ aiohttp-sqlalchemy's documentation :target: https://www.codacy.com/gh/ri-gilfanov/aiohttp-sqlalchemy/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ri-gilfanov/aiohttp-sqlalchemy&utm_campaign=Badge_Grade :alt: Codacy code quality -`SQLAlchemy 1.4 / 2.0 `_ support for `AIOHTTP +`SQLAlchemy 2.0 `_ support for `AIOHTTP `_. The library provides the next features: diff --git a/docs/quickstart.rst b/docs/quickstart.rst index 2828e6a..6fcff76 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -77,7 +77,7 @@ More control in configuration url = 'sqlite+aiosqlite:///' engine = create_async_engine(url, echo=True) - Session = orm.sessionmaker(main_engine, AsyncSession, expire_on_commit=False) + Session = orm.sessionmaker(main_engine, class_=AsyncSession, expire_on_commit=False) ahsa.setup(app, [ ahsa.bind(Session), diff --git a/docs/releases.rst b/docs/releases.rst index 663faae..681bf73 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -1,11 +1,21 @@ ======== Releases ======== +Version 1.0.0 +------------- +**Added** + +* Added support for SQLAlchemy 2.0. + +**Removed** + +* Dropped support for SQLAlchemy 1.4. + Version 0.35 ------------ **Added** -* Python 3.11 and 3.12 support. +* Added support for Python 3.11 and 3.12. **Changed** @@ -13,7 +23,7 @@ Version 0.35 **Removed** -* Python 3.7 support. +* Dropped support for Python 3.7. Version 0.34 ------------ diff --git a/examples/test_example.py b/examples/test_example.py index b081883..164f4cb 100644 --- a/examples/test_example.py +++ b/examples/test_example.py @@ -43,10 +43,7 @@ async def select_instances(session): stmt = sa.select(MyModel) result = await session.execute(stmt) instances = result.scalars() - return { - instance.pk: instance.timestamp.isoformat() - for instance in instances - } + return {instance.pk: instance.timestamp.isoformat() for instance in instances} @sa_decorator(THIRD_KEY) @@ -54,10 +51,7 @@ async def select_instances(session): async def function_handler(request): await add_instance(sa_session(request, choice(KEY_LIST))) return web.json_response( - { - key: await select_instances(sa_session(request, key)) - for key in KEY_LIST - } + {key: await select_instances(sa_session(request, key)) for key in KEY_LIST} ) @@ -67,10 +61,7 @@ class ClassOrganizedHandler: async def get(self, request): await add_instance(sa_session(request, choice(KEY_LIST))) return web.json_response( - { - key: await select_instances(sa_session(request, key)) - for key in KEY_LIST - } + {key: await select_instances(sa_session(request, key)) for key in KEY_LIST} ) @@ -80,10 +71,7 @@ class ClassBasedView(web.View, SAMixin): async def get(self): await add_instance(self.get_sa_session(choice(KEY_LIST))) return web.json_response( - { - key: await select_instances(self.get_sa_session(key)) - for key in KEY_LIST - } + {key: await select_instances(self.get_sa_session(key)) for key in KEY_LIST} ) diff --git a/poetry.lock b/poetry.lock index 35c73c9..e8abcf6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -125,17 +125,17 @@ speedups = ["Brotli", "aiodns (>=3.2.0)", "brotlicffi"] [[package]] name = "aiohttp-things" -version = "0.14.0" +version = "1.0.0" description = "Modest utility collection for development with AIOHTTP framework." optional = false -python-versions = ">=3.7,<4.0" +python-versions = "<4.0,>=3.8" files = [ - {file = "aiohttp-things-0.14.0.tar.gz", hash = "sha256:7691fa92cf86767ab64352d45961c9e5012297716f93a0f3f189ae7d5aa9fb92"}, - {file = "aiohttp_things-0.14.0-py3-none-any.whl", hash = "sha256:a421bc734826c0034373809ea3a6ef245ea7806178cedefe487a7d7302fd8de0"}, + {file = "aiohttp_things-1.0.0-py3-none-any.whl", hash = "sha256:dab325f5d5b9d286ca4a3b1243f963d50e623142c6aa0e819d5b9a0f70a9dc17"}, + {file = "aiohttp_things-1.0.0.tar.gz", hash = "sha256:75af32b77b51257e2f107527bafc2ad00c394ad65375c01c1c2001f304745f59"}, ] [package.dependencies] -aiohttp = ">=3.7.4.post0,<4.0.0" +aiohttp = ">=3.10.5,<4.0.0" [[package]] name = "aiomysql" @@ -1331,99 +1331,109 @@ test = ["pytest"] [[package]] name = "sqlalchemy" -version = "1.4.54" +version = "2.0.34" description = "Database Abstraction Library" optional = false -python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7" +python-versions = ">=3.7" files = [ - {file = "SQLAlchemy-1.4.54-cp310-cp310-macosx_12_0_x86_64.whl", hash = "sha256:af00236fe21c4d4f4c227b6ccc19b44c594160cc3ff28d104cdce85855369277"}, - {file = "SQLAlchemy-1.4.54-cp310-cp310-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1183599e25fa38a1a322294b949da02b4f0da13dbc2688ef9dbe746df573f8a6"}, - {file = "SQLAlchemy-1.4.54-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1990d5a6a5dc358a0894c8ca02043fb9a5ad9538422001fb2826e91c50f1d539"}, - {file = "SQLAlchemy-1.4.54-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:14b3f4783275339170984cadda66e3ec011cce87b405968dc8d51cf0f9997b0d"}, - {file = "SQLAlchemy-1.4.54-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6b24364150738ce488333b3fb48bfa14c189a66de41cd632796fbcacb26b4585"}, - {file = "SQLAlchemy-1.4.54-cp310-cp310-win32.whl", hash = "sha256:a8a72259a1652f192c68377be7011eac3c463e9892ef2948828c7d58e4829988"}, - {file = "SQLAlchemy-1.4.54-cp310-cp310-win_amd64.whl", hash = "sha256:b67589f7955924865344e6eacfdcf70675e64f36800a576aa5e961f0008cde2a"}, - {file = "SQLAlchemy-1.4.54-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:b05e0626ec1c391432eabb47a8abd3bf199fb74bfde7cc44a26d2b1b352c2c6e"}, - {file = "SQLAlchemy-1.4.54-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:13e91d6892b5fcb94a36ba061fb7a1f03d0185ed9d8a77c84ba389e5bb05e936"}, - {file = "SQLAlchemy-1.4.54-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fb59a11689ff3c58e7652260127f9e34f7f45478a2f3ef831ab6db7bcd72108f"}, - {file = "SQLAlchemy-1.4.54-cp311-cp311-win32.whl", hash = "sha256:1390ca2d301a2708fd4425c6d75528d22f26b8f5cbc9faba1ddca136671432bc"}, - {file = "SQLAlchemy-1.4.54-cp311-cp311-win_amd64.whl", hash = "sha256:2b37931eac4b837c45e2522066bda221ac6d80e78922fb77c75eb12e4dbcdee5"}, - {file = "SQLAlchemy-1.4.54-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:3f01c2629a7d6b30d8afe0326b8c649b74825a0e1ebdcb01e8ffd1c920deb07d"}, - {file = "SQLAlchemy-1.4.54-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9c24dd161c06992ed16c5e528a75878edbaeced5660c3db88c820f1f0d3fe1f4"}, - {file = "SQLAlchemy-1.4.54-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b5e0d47d619c739bdc636bbe007da4519fc953393304a5943e0b5aec96c9877c"}, - {file = "SQLAlchemy-1.4.54-cp312-cp312-win32.whl", hash = "sha256:12bc0141b245918b80d9d17eca94663dbd3f5266ac77a0be60750f36102bbb0f"}, - {file = "SQLAlchemy-1.4.54-cp312-cp312-win_amd64.whl", hash = "sha256:f941aaf15f47f316123e1933f9ea91a6efda73a161a6ab6046d1cde37be62c88"}, - {file = "SQLAlchemy-1.4.54-cp36-cp36m-macosx_10_14_x86_64.whl", hash = "sha256:a41611835010ed4ea4c7aed1da5b58aac78ee7e70932a91ed2705a7b38e40f52"}, - {file = "SQLAlchemy-1.4.54-cp36-cp36m-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1e8c1b9ecaf9f2590337d5622189aeb2f0dbc54ba0232fa0856cf390957584a9"}, - {file = "SQLAlchemy-1.4.54-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0de620f978ca273ce027769dc8db7e6ee72631796187adc8471b3c76091b809e"}, - {file = "SQLAlchemy-1.4.54-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:c5a2530400a6e7e68fd1552a55515de6a4559122e495f73554a51cedafc11669"}, - {file = "SQLAlchemy-1.4.54-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d0cf7076c8578b3de4e43a046cc7a1af8466e1c3f5e64167189fe8958a4f9c02"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-macosx_11_0_x86_64.whl", hash = "sha256:f1e1b92ee4ee9ffc68624ace218b89ca5ca667607ccee4541a90cc44999b9aea"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:41cffc63c7c83dfc30c4cab5b4308ba74440a9633c4509c51a0c52431fb0f8ab"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b5933c45d11cbd9694b1540aa9076816cc7406964c7b16a380fd84d3a5fe3241"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:cafe0ba3a96d0845121433cffa2b9232844a2609fce694fcc02f3f31214ece28"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a19f816f4702d7b1951d7576026c7124b9bfb64a9543e571774cf517b7a50b29"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-win32.whl", hash = "sha256:76c2ba7b5a09863d0a8166fbc753af96d561818c572dbaf697c52095938e7be4"}, - {file = "SQLAlchemy-1.4.54-cp37-cp37m-win_amd64.whl", hash = "sha256:a86b0e4be775902a5496af4fb1b60d8a2a457d78f531458d294360b8637bb014"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-macosx_12_0_x86_64.whl", hash = "sha256:a49730afb716f3f675755afec109895cab95bc9875db7ffe2e42c1b1c6279482"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:26e78444bc77d089e62874dc74df05a5c71f01ac598010a327881a48408d0064"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:02d2ecb9508f16ab9c5af466dfe5a88e26adf2e1a8d1c56eb616396ccae2c186"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:394b0135900b62dbf63e4809cdc8ac923182af2816d06ea61cd6763943c2cc05"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5ed3576675c187e3baa80b02c4c9d0edfab78eff4e89dd9da736b921333a2432"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-win32.whl", hash = "sha256:fc9ffd9a38e21fad3e8c5a88926d57f94a32546e937e0be46142b2702003eba7"}, - {file = "SQLAlchemy-1.4.54-cp38-cp38-win_amd64.whl", hash = "sha256:a01bc25eb7a5688656c8770f931d5cb4a44c7de1b3cec69b84cc9745d1e4cc10"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-macosx_12_0_x86_64.whl", hash = "sha256:0b76bbb1cbae618d10679be8966f6d66c94f301cfc15cb49e2f2382563fb6efb"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-manylinux1_x86_64.manylinux2010_x86_64.manylinux_2_12_x86_64.manylinux_2_5_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cdb2886c0be2c6c54d0651d5a61c29ef347e8eec81fd83afebbf7b59b80b7393"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:954816850777ac234a4e32b8c88ac1f7847088a6e90cfb8f0e127a1bf3feddff"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:1d83cd1cc03c22d922ec94d0d5f7b7c96b1332f5e122e81b1a61fb22da77879a"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1576fba3616f79496e2f067262200dbf4aab1bb727cd7e4e006076686413c80c"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-win32.whl", hash = "sha256:3112de9e11ff1957148c6de1df2bc5cc1440ee36783412e5eedc6f53638a577d"}, - {file = "SQLAlchemy-1.4.54-cp39-cp39-win_amd64.whl", hash = "sha256:6da60fb24577f989535b8fc8b2ddc4212204aaf02e53c4c7ac94ac364150ed08"}, - {file = "sqlalchemy-1.4.54.tar.gz", hash = "sha256:4470fbed088c35dc20b78a39aaf4ae54fe81790c783b3264872a0224f437c31a"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:95d0b2cf8791ab5fb9e3aa3d9a79a0d5d51f55b6357eecf532a120ba3b5524db"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:243f92596f4fd4c8bd30ab8e8dd5965afe226363d75cab2468f2c707f64cd83b"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9ea54f7300553af0a2a7235e9b85f4204e1fc21848f917a3213b0e0818de9a24"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:173f5f122d2e1bff8fbd9f7811b7942bead1f5e9f371cdf9e670b327e6703ebd"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:196958cde924a00488e3e83ff917be3b73cd4ed8352bbc0f2989333176d1c54d"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:bd90c221ed4e60ac9d476db967f436cfcecbd4ef744537c0f2d5291439848768"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-win32.whl", hash = "sha256:3166dfff2d16fe9be3241ee60ece6fcb01cf8e74dd7c5e0b64f8e19fab44911b"}, + {file = "SQLAlchemy-2.0.34-cp310-cp310-win_amd64.whl", hash = "sha256:6831a78bbd3c40f909b3e5233f87341f12d0b34a58f14115c9e94b4cdaf726d3"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c7db3db284a0edaebe87f8f6642c2b2c27ed85c3e70064b84d1c9e4ec06d5d84"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:430093fce0efc7941d911d34f75a70084f12f6ca5c15d19595c18753edb7c33b"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:79cb400c360c7c210097b147c16a9e4c14688a6402445ac848f296ade6283bbc"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fb1b30f31a36c7f3fee848391ff77eebdd3af5750bf95fbf9b8b5323edfdb4ec"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8fddde2368e777ea2a4891a3fb4341e910a056be0bb15303bf1b92f073b80c02"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:80bd73ea335203b125cf1d8e50fef06be709619eb6ab9e7b891ea34b5baa2287"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-win32.whl", hash = "sha256:6daeb8382d0df526372abd9cb795c992e18eed25ef2c43afe518c73f8cccb721"}, + {file = "SQLAlchemy-2.0.34-cp311-cp311-win_amd64.whl", hash = "sha256:5bc08e75ed11693ecb648b7a0a4ed80da6d10845e44be0c98c03f2f880b68ff4"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:53e68b091492c8ed2bd0141e00ad3089bcc6bf0e6ec4142ad6505b4afe64163e"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:bcd18441a49499bf5528deaa9dee1f5c01ca491fc2791b13604e8f972877f812"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:165bbe0b376541092bf49542bd9827b048357f4623486096fc9aaa6d4e7c59a2"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c3330415cd387d2b88600e8e26b510d0370db9b7eaf984354a43e19c40df2e2b"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:97b850f73f8abbffb66ccbab6e55a195a0eb655e5dc74624d15cff4bfb35bd74"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:7cee4c6917857fd6121ed84f56d1dc78eb1d0e87f845ab5a568aba73e78adf83"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-win32.whl", hash = "sha256:fbb034f565ecbe6c530dff948239377ba859420d146d5f62f0271407ffb8c580"}, + {file = "SQLAlchemy-2.0.34-cp312-cp312-win_amd64.whl", hash = "sha256:707c8f44931a4facd4149b52b75b80544a8d824162602b8cd2fe788207307f9a"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:24af3dc43568f3780b7e1e57c49b41d98b2d940c1fd2e62d65d3928b6f95f021"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e60ed6ef0a35c6b76b7640fe452d0e47acc832ccbb8475de549a5cc5f90c2c06"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:413c85cd0177c23e32dee6898c67a5f49296640041d98fddb2c40888fe4daa2e"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-musllinux_1_2_aarch64.whl", hash = "sha256:25691f4adfb9d5e796fd48bf1432272f95f4bbe5f89c475a788f31232ea6afba"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-musllinux_1_2_x86_64.whl", hash = "sha256:526ce723265643dbc4c7efb54f56648cc30e7abe20f387d763364b3ce7506c82"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-win32.whl", hash = "sha256:13be2cc683b76977a700948411a94c67ad8faf542fa7da2a4b167f2244781cf3"}, + {file = "SQLAlchemy-2.0.34-cp37-cp37m-win_amd64.whl", hash = "sha256:e54ef33ea80d464c3dcfe881eb00ad5921b60f8115ea1a30d781653edc2fd6a2"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:43f28005141165edd11fbbf1541c920bd29e167b8bbc1fb410d4fe2269c1667a"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b68094b165a9e930aedef90725a8fcfafe9ef95370cbb54abc0464062dbf808f"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6a1e03db964e9d32f112bae36f0cc1dcd1988d096cfd75d6a588a3c3def9ab2b"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:203d46bddeaa7982f9c3cc693e5bc93db476ab5de9d4b4640d5c99ff219bee8c"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:ae92bebca3b1e6bd203494e5ef919a60fb6dfe4d9a47ed2453211d3bd451b9f5"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:9661268415f450c95f72f0ac1217cc6f10256f860eed85c2ae32e75b60278ad8"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-win32.whl", hash = "sha256:895184dfef8708e15f7516bd930bda7e50ead069280d2ce09ba11781b630a434"}, + {file = "SQLAlchemy-2.0.34-cp38-cp38-win_amd64.whl", hash = "sha256:6e7cde3a2221aa89247944cafb1b26616380e30c63e37ed19ff0bba5e968688d"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:dbcdf987f3aceef9763b6d7b1fd3e4ee210ddd26cac421d78b3c206d07b2700b"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:ce119fc4ce0d64124d37f66a6f2a584fddc3c5001755f8a49f1ca0a177ef9796"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a17d8fac6df9835d8e2b4c5523666e7051d0897a93756518a1fe101c7f47f2f0"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9ebc11c54c6ecdd07bb4efbfa1554538982f5432dfb8456958b6d46b9f834bb7"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:2e6965346fc1491a566e019a4a1d3dfc081ce7ac1a736536367ca305da6472a8"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:220574e78ad986aea8e81ac68821e47ea9202b7e44f251b7ed8c66d9ae3f4278"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-win32.whl", hash = "sha256:b75b00083e7fe6621ce13cfce9d4469c4774e55e8e9d38c305b37f13cf1e874c"}, + {file = "SQLAlchemy-2.0.34-cp39-cp39-win_amd64.whl", hash = "sha256:c29d03e0adf3cc1a8c3ec62d176824972ae29b67a66cbb18daff3062acc6faa8"}, + {file = "SQLAlchemy-2.0.34-py3-none-any.whl", hash = "sha256:7286c353ee6475613d8beff83167374006c6b3e3f0e6491bfe8ca610eb1dec0f"}, + {file = "sqlalchemy-2.0.34.tar.gz", hash = "sha256:10d8f36990dd929690666679b0f42235c159a7051534adb135728ee52828dd22"}, ] [package.dependencies] -greenlet = {version = "!=0.4.17", markers = "python_version >= \"3\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"} +greenlet = {version = "!=0.4.17", markers = "python_version < \"3.13\" and (platform_machine == \"aarch64\" or platform_machine == \"ppc64le\" or platform_machine == \"x86_64\" or platform_machine == \"amd64\" or platform_machine == \"AMD64\" or platform_machine == \"win32\" or platform_machine == \"WIN32\")"} +typing-extensions = ">=4.6.0" [package.extras] aiomysql = ["aiomysql (>=0.2.0)", "greenlet (!=0.4.17)"] +aioodbc = ["aioodbc", "greenlet (!=0.4.17)"] aiosqlite = ["aiosqlite", "greenlet (!=0.4.17)", "typing_extensions (!=3.10.0.1)"] asyncio = ["greenlet (!=0.4.17)"] -asyncmy = ["asyncmy (>=0.2.3,!=0.2.4)", "greenlet (!=0.4.17)"] -mariadb-connector = ["mariadb (>=1.0.1,!=1.1.2)", "mariadb (>=1.0.1,!=1.1.2)"] +asyncmy = ["asyncmy (>=0.2.3,!=0.2.4,!=0.2.6)", "greenlet (!=0.4.17)"] +mariadb-connector = ["mariadb (>=1.0.1,!=1.1.2,!=1.1.5)"] mssql = ["pyodbc"] -mssql-pymssql = ["pymssql", "pymssql"] -mssql-pyodbc = ["pyodbc", "pyodbc"] -mypy = ["mypy (>=0.910)", "sqlalchemy2-stubs"] -mysql = ["mysqlclient (>=1.4.0)", "mysqlclient (>=1.4.0,<2)"] -mysql-connector = ["mysql-connector-python", "mysql-connector-python"] -oracle = ["cx_oracle (>=7)", "cx_oracle (>=7,<8)"] +mssql-pymssql = ["pymssql"] +mssql-pyodbc = ["pyodbc"] +mypy = ["mypy (>=0.910)"] +mysql = ["mysqlclient (>=1.4.0)"] +mysql-connector = ["mysql-connector-python"] +oracle = ["cx_oracle (>=8)"] +oracle-oracledb = ["oracledb (>=1.0.1)"] postgresql = ["psycopg2 (>=2.7)"] -postgresql-asyncpg = ["asyncpg", "asyncpg", "greenlet (!=0.4.17)", "greenlet (!=0.4.17)"] -postgresql-pg8000 = ["pg8000 (>=1.16.6,!=1.29.0)", "pg8000 (>=1.16.6,!=1.29.0)"] +postgresql-asyncpg = ["asyncpg", "greenlet (!=0.4.17)"] +postgresql-pg8000 = ["pg8000 (>=1.29.1)"] +postgresql-psycopg = ["psycopg (>=3.0.7)"] postgresql-psycopg2binary = ["psycopg2-binary"] postgresql-psycopg2cffi = ["psycopg2cffi"] -pymysql = ["pymysql", "pymysql (<1)"] +postgresql-psycopgbinary = ["psycopg[binary] (>=3.0.7)"] +pymysql = ["pymysql"] sqlcipher = ["sqlcipher3_binary"] [[package]] name = "sqlalchemy-things" -version = "0.10.2" +version = "1.0.0" description = "Utility collection for development with SQLalchemy ORM." optional = false -python-versions = ">=3.7,<4.0" +python-versions = "<4.0,>=3.8" files = [ - {file = "sqlalchemy-things-0.10.2.tar.gz", hash = "sha256:1e054a32e343228685c81f9287e6aa180f5ebaa63ef87e83a1b9c825749ef98a"}, - {file = "sqlalchemy_things-0.10.2-py3-none-any.whl", hash = "sha256:d5ebe591e2558d7873bc604416a47e2a345eb437570eaa6ded5ed81c3a763574"}, + {file = "sqlalchemy_things-1.0.0-py3-none-any.whl", hash = "sha256:7099030d0154e904f232b8339ed27e003e3d184ff0b769674ab6017352d77d9a"}, + {file = "sqlalchemy_things-1.0.0.tar.gz", hash = "sha256:64f37140bbbfc53b5786336e615d24dfe6bf756b2711a0f7505697f49134f49c"}, ] [package.dependencies] -sqlalchemy = ">=1.4.21,<2.0.0" +sqlalchemy = ">=2.0.34,<3.0.0" [package.extras] -mysql = ["aiomysql (>=0.0.21)"] -postgresql = ["asyncpg (>=0.23.0)"] -sqlite = ["aiosqlite (>=0.17.0)"] +mysql = ["aiomysql (>=0.2.0)"] +postgresql = ["asyncpg (>=0.29.0)"] +sqlite = ["aiosqlite (>=0.20.0)"] [[package]] name = "tomli" @@ -1596,4 +1606,4 @@ sqlite = ["aiosqlite"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "446d3b289d784f3bc1a7709c56485791c54be03c7159f734378580878628c757" +content-hash = "740fb7398e23431d9f2135bdb97983f2a3542149c315dda19a3cb875da42a30d" diff --git a/pyproject.toml b/pyproject.toml index 2a3becb..af654f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,8 @@ [tool.poetry] name = "aiohttp-sqlalchemy" -version = "0.35.0" -description = "SQLAlchemy 1.4 / 2.0 support for aiohttp." +packages = [{include = "aiohttp_sqlalchemy", from = "src" }] +version = "1.0.0" +description = "SQLAlchemy 2.0 support for aiohttp." license = "MIT" authors = [ @@ -28,6 +29,8 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Database", "Topic :: Database :: Front-Ends", "Topic :: Internet", @@ -41,8 +44,8 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.8" aiohttp = "^3.10.5" -aiohttp-things = "==0.14.0" -sqlalchemy-things = "==0.10.2" +aiohttp-things = "^1.0.0" +sqlalchemy-things = "^1.0.0" aiomysql = { version = ">=0.2.0", optional = true } aiosqlite = { version = ">=0.20.0", optional = true } asyncpg = { version = ">=0.29.0", optional = true } @@ -69,15 +72,10 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.mypy] -files = ["aiohttp_sqlalchemy", "tests"] -plugins = "sqlalchemy.ext.mypy.plugin" - -[[tool.mypy.overrides]] -module = ['sqlalchemy.*'] -ignore_missing_imports = true +files = ["src", "tests"] [tool.ruff] -line-length = 79 +line-length = 88 [tool.ruff.lint] select = ["ALL"] diff --git a/aiohttp_sqlalchemy/__init__.py b/src/aiohttp_sqlalchemy/__init__.py similarity index 96% rename from aiohttp_sqlalchemy/__init__.py rename to src/aiohttp_sqlalchemy/__init__.py index 9bbdb91..89b78c8 100644 --- a/aiohttp_sqlalchemy/__init__.py +++ b/src/aiohttp_sqlalchemy/__init__.py @@ -1,4 +1,4 @@ -"""AIOHTTP-SQLAlchemy. SQLAlchemy 1.4 / 2.0 support for aiohttp.""" +"""AIOHTTP-SQLAlchemy. SQLAlchemy 2.0 support for aiohttp.""" from __future__ import annotations @@ -110,7 +110,7 @@ def bind( target = create_async_engine(target) if isinstance(target, AsyncEngine): - target = sessionmaker( + target = sessionmaker( # type: ignore bind=target, class_=AsyncSession, expire_on_commit=False, diff --git a/aiohttp_sqlalchemy/constants.py b/src/aiohttp_sqlalchemy/constants.py similarity index 100% rename from aiohttp_sqlalchemy/constants.py rename to src/aiohttp_sqlalchemy/constants.py diff --git a/aiohttp_sqlalchemy/decorators.py b/src/aiohttp_sqlalchemy/decorators.py similarity index 89% rename from aiohttp_sqlalchemy/decorators.py rename to src/aiohttp_sqlalchemy/decorators.py index 0e61329..7d78774 100644 --- a/aiohttp_sqlalchemy/decorators.py +++ b/src/aiohttp_sqlalchemy/decorators.py @@ -23,11 +23,7 @@ def sa_decorator(key: str = SA_DEFAULT_KEY) -> THandlerWrapper: def wrapper(handler: THandler) -> THandler: @wraps(handler) async def wrapped(*args: Any, **kwargs: Any) -> StreamResponse: - request = ( - args[0].request - if isinstance(args[0], AbstractView) - else args[-1] - ) + request = args[0].request if isinstance(args[0], AbstractView) else args[-1] if key in request: raise DuplicateRequestKeyError(key) diff --git a/aiohttp_sqlalchemy/exceptions.py b/src/aiohttp_sqlalchemy/exceptions.py similarity index 100% rename from aiohttp_sqlalchemy/exceptions.py rename to src/aiohttp_sqlalchemy/exceptions.py diff --git a/aiohttp_sqlalchemy/middlewares.py b/src/aiohttp_sqlalchemy/middlewares.py similarity index 100% rename from aiohttp_sqlalchemy/middlewares.py rename to src/aiohttp_sqlalchemy/middlewares.py diff --git a/aiohttp_sqlalchemy/py.typed b/src/aiohttp_sqlalchemy/py.typed similarity index 100% rename from aiohttp_sqlalchemy/py.typed rename to src/aiohttp_sqlalchemy/py.typed diff --git a/aiohttp_sqlalchemy/typedefs.py b/src/aiohttp_sqlalchemy/typedefs.py similarity index 63% rename from aiohttp_sqlalchemy/typedefs.py rename to src/aiohttp_sqlalchemy/typedefs.py index 2b2f763..1e50fcc 100644 --- a/aiohttp_sqlalchemy/typedefs.py +++ b/src/aiohttp_sqlalchemy/typedefs.py @@ -2,11 +2,11 @@ from aiohttp.web import StreamResponse from sqlalchemy.ext.asyncio import AsyncEngine -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import Session, sessionmaker THandler = Callable[..., Awaitable[StreamResponse]] THandlerWrapper = Callable[..., THandler] -TTarget = Union[str, AsyncEngine, sessionmaker] -TBind = Tuple[sessionmaker, str, bool] +TTarget = Union[str, AsyncEngine, sessionmaker[Session]] +TBind = Tuple[sessionmaker[Session], str, bool] TBinds = Iterable[TBind] diff --git a/aiohttp_sqlalchemy/utils.py b/src/aiohttp_sqlalchemy/utils.py similarity index 86% rename from aiohttp_sqlalchemy/utils.py rename to src/aiohttp_sqlalchemy/utils.py index d2645a0..b2a476c 100644 --- a/aiohttp_sqlalchemy/utils.py +++ b/src/aiohttp_sqlalchemy/utils.py @@ -9,7 +9,7 @@ if TYPE_CHECKING: # pragma: no cover from sqlalchemy import MetaData - from sqlalchemy.orm import sessionmaker + from sqlalchemy.orm import Session, sessionmaker async def init_db( @@ -38,7 +38,7 @@ async def get_engine( :param key: key of SQLAlchemy binding. """ session_factory = get_session_factory(app, key) - return session_factory.kw.get("bind") + return session_factory.kw.get("bind") # type: ignore def get_session( @@ -64,7 +64,7 @@ def get_session( def get_session_factory( source: Request | Application, key: str = SA_DEFAULT_KEY, -) -> sessionmaker: +) -> sessionmaker[Session]: """Return callable object which returns an `AsyncSession` instance. :param source: AIOHTTP request object or your AIOHTTP application. @@ -72,13 +72,12 @@ def get_session_factory( """ if not isinstance(source, (Request, Application)): msg = ( - "Arg `source` must be `aiohttp.web.Application`" - "or `aiohttp.web.Request`." + "Arg `source` must be `aiohttp.web.Application`" "or `aiohttp.web.Request`." ) raise TypeError(msg) if isinstance(source, Request): - return source.config_dict.get(key) - return source.get(key) + return source.config_dict.get(key) # type: ignore + return source.get(key) # type: ignore # Synonyms diff --git a/aiohttp_sqlalchemy/web_handlers.py b/src/aiohttp_sqlalchemy/web_handlers.py similarity index 97% rename from aiohttp_sqlalchemy/web_handlers.py rename to src/aiohttp_sqlalchemy/web_handlers.py index c0c0827..6f1dd2e 100644 --- a/aiohttp_sqlalchemy/web_handlers.py +++ b/src/aiohttp_sqlalchemy/web_handlers.py @@ -39,7 +39,7 @@ def get_update_stmt(self, model: Any = None) -> Update: class SelectStatementMixin(SAModelMixin): - def get_select_stmt(self, model: Any = None) -> Select: + def get_select_stmt(self, model: Any = None) -> Select[Any]: return select(model or self.sa_model) @@ -115,7 +115,7 @@ class UnitViewMixin( PrimaryKeyMixin, metaclass=ABCMeta, ): - def get_select_stmt(self, model: Any = None) -> Select: + def get_select_stmt(self, model: Any = None) -> Select[Any]: return super().get_select_stmt(model).where(self.sa_pk_attr == self.pk) diff --git a/tests/conftest.py b/tests/conftest.py index 1ec5acf..d9146f7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,21 +1,29 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any + import pytest import sqlalchemy as sa from aiohttp import web from aiohttp.hdrs import METH_GET from aiohttp.test_utils import make_mocked_request from aiohttp.web import Request, Response -from aiohttp.web_app import Application from sqlalchemy import orm from sqlalchemy.ext.asyncio import ( AsyncEngine, AsyncSession, create_async_engine, ) -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import Session, sessionmaker import aiohttp_sqlalchemy from aiohttp_sqlalchemy import SA_DEFAULT_KEY, sa_bind, sa_middleware -from aiohttp_sqlalchemy.typedefs import THandler + +if TYPE_CHECKING: # pragma: no cover + from aiohttp.web_app import Application + + from aiohttp_sqlalchemy.typedefs import THandler + pytest_plugins = "aiohttp.pytest_plugin" @@ -26,9 +34,9 @@ def wrong_key() -> str: @pytest.fixture -def base_model() -> orm.Mapper: +def base_model() -> orm.Mapper[Any]: metadata = sa.MetaData() - return orm.declarative_base(metadata=metadata) + return orm.declarative_base(metadata=metadata) # type: ignore @pytest.fixture @@ -37,12 +45,15 @@ def orm_async_engine() -> AsyncEngine: @pytest.fixture -def session_factory(orm_async_engine: AsyncEngine) -> sessionmaker: - return sessionmaker(orm_async_engine, AsyncSession) +def session_factory(orm_async_engine: AsyncEngine) -> sessionmaker[Session]: + return sessionmaker(orm_async_engine, class_=AsyncSession) # type: ignore @pytest.fixture -def session(session_factory: sessionmaker) -> AsyncSession: +def session(session_factory: sessionmaker[Session]) -> AsyncSession: + session = session_factory() + if not isinstance(session, AsyncSession): + raise TypeError return session_factory() @@ -52,14 +63,14 @@ def main_middleware() -> THandler: @pytest.fixture -def middlewared_app(session_factory: sessionmaker) -> Application: +def middlewared_app(session_factory: sessionmaker[Session]) -> Application: app = web.Application() aiohttp_sqlalchemy.setup(app, [sa_bind(session_factory)]) return app @pytest.fixture -def mocked_request(middlewared_app: Application) -> "Request": +def mocked_request(middlewared_app: Application) -> Request: return make_mocked_request(METH_GET, "/", app=middlewared_app) diff --git a/tests/test_aiohttp_sqlalchemy.py b/tests/test_aiohttp_sqlalchemy.py index 86ae197..b69c01d 100644 --- a/tests/test_aiohttp_sqlalchemy.py +++ b/tests/test_aiohttp_sqlalchemy.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from pathlib import Path import tomli diff --git a/tests/test_bind.py b/tests/test_bind.py index c84c723..5634b8b 100644 --- a/tests/test_bind.py +++ b/tests/test_bind.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import pytest from sqlalchemy import create_engine from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession @@ -23,13 +25,13 @@ def test_bind_to_async_engine(orm_async_engine: AsyncEngine) -> None: def test_bind_to_sync_engine() -> None: engine = create_engine("sqlite+aiosqlite:///") with pytest.raises(TypeError): - aiohttp_sqlalchemy.bind(engine) + aiohttp_sqlalchemy.bind(engine) # type: ignore def test_bind_with_ready_session(orm_async_engine: AsyncEngine) -> None: session = AsyncSession(orm_async_engine) with pytest.raises(TypeError): - aiohttp_sqlalchemy.bind(session) + aiohttp_sqlalchemy.bind(session) # type: ignore def test_bind_with_sync_session() -> None: @@ -37,11 +39,11 @@ def test_bind_with_sync_session() -> None: Session = sessionmaker(engine) session = Session() with pytest.raises(TypeError): - aiohttp_sqlalchemy.bind(session) + aiohttp_sqlalchemy.bind(session) # type: ignore def test_bind_to_async_session_maker(orm_async_engine: AsyncEngine) -> None: - Session = sessionmaker(orm_async_engine, AsyncSession) + Session = sessionmaker(orm_async_engine, class_=AsyncSession) # type: ignore binding = aiohttp_sqlalchemy.bind(Session) Session = binding[0] session = Session() @@ -50,4 +52,4 @@ def test_bind_to_async_session_maker(orm_async_engine: AsyncEngine) -> None: def test_bind_to_none() -> None: with pytest.raises(TypeError): - aiohttp_sqlalchemy.bind(None) + aiohttp_sqlalchemy.bind(None) # type: ignore diff --git a/tests/test_constants.py b/tests/test_constants.py index fdc4054..6baee9d 100644 --- a/tests/test_constants.py +++ b/tests/test_constants.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import aiohttp_sqlalchemy from aiohttp_sqlalchemy import constants diff --git a/tests/test_decorators.py b/tests/test_decorators.py index 208e83b..e0440ce 100644 --- a/tests/test_decorators.py +++ b/tests/test_decorators.py @@ -1,5 +1,8 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pytest -from aiohttp.web import Request from sqlalchemy.ext.asyncio import AsyncSession from aiohttp_sqlalchemy import ( @@ -7,9 +10,13 @@ DuplicateRequestKeyError, sa_decorator, ) -from aiohttp_sqlalchemy.typedefs import THandler from tests.conftest import ClassBasedView, ClassHandler +if TYPE_CHECKING: # pragma: no cover + from aiohttp.web import Request + + from aiohttp_sqlalchemy.typedefs import THandler + async def test_duplicate_request_key_error( mocked_request: Request, diff --git a/tests/test_middlewares.py b/tests/test_middlewares.py index b0fdefb..164a9eb 100644 --- a/tests/test_middlewares.py +++ b/tests/test_middlewares.py @@ -1,5 +1,8 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pytest -from aiohttp.web import Request from sqlalchemy.ext.asyncio import AsyncSession from aiohttp_sqlalchemy import ( @@ -7,7 +10,11 @@ DuplicateRequestKeyError, sa_middleware, ) -from aiohttp_sqlalchemy.typedefs import THandler + +if TYPE_CHECKING: # pragma: no cover + from aiohttp.web import Request + + from aiohttp_sqlalchemy.typedefs import THandler async def test_duplicate_request_key_error( diff --git a/tests/test_setup.py b/tests/test_setup.py index 3675aca..91fe20b 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -1,13 +1,20 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pytest from aiohttp import web -from sqlalchemy.orm import sessionmaker + +if TYPE_CHECKING: # pragma: no cover + from sqlalchemy.orm import Session, sessionmaker + import aiohttp_sqlalchemy from aiohttp_sqlalchemy import DuplicateAppKeyError async def test_duplicate_app_key_error( - session_factory: sessionmaker, + session_factory: sessionmaker[Session], ) -> None: with pytest.raises(DuplicateAppKeyError): aiohttp_sqlalchemy.setup( diff --git a/tests/test_utils.py b/tests/test_utils.py index e4d6b3e..a50aadc 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,11 +1,17 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + import pytest import sqlalchemy as sa -from aiohttp.web import Application, Request from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession -from sqlalchemy.orm import sessionmaker import aiohttp_sqlalchemy as ahsa +if TYPE_CHECKING: # pragma: no cover + from aiohttp.web import Application, Request + from sqlalchemy.orm import Session, sessionmaker + async def test_db_init(middlewared_app: Application) -> None: metadata = sa.MetaData() @@ -31,7 +37,7 @@ def test_get_session(mocked_request: Request, session: AsyncSession) -> None: def test_get_session_factory( mocked_request: Request, middlewared_app: Application, - session_factory: sessionmaker, + session_factory: sessionmaker[Session], ) -> None: assert ahsa.get_session_factory(mocked_request) is session_factory assert ahsa.get_session_factory(middlewared_app) is session_factory diff --git a/tests/test_web_handlers.py b/tests/test_web_handlers.py index 4ec5aea..d6a0d55 100644 --- a/tests/test_web_handlers.py +++ b/tests/test_web_handlers.py @@ -1,13 +1,19 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING, Any + import pytest import sqlalchemy as sa from aiohttp import web from aiohttp.hdrs import METH_GET from aiohttp.test_utils import make_mocked_request -from aiohttp.web import Request from sqlalchemy import orm -from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy_things.pagination import OffsetPage +if TYPE_CHECKING: # pragma: no cover + from aiohttp.web import Request + from sqlalchemy.ext.asyncio import AsyncSession + from aiohttp_sqlalchemy import ( SA_DEFAULT_KEY, ListAddMixin, @@ -35,7 +41,7 @@ def test_sa_session( def test_instance_add( mocked_request: Request, session: AsyncSession, - base_model: orm.Mapper, + base_model: orm.Mapper[Any], ) -> None: class Model(base_model): # type: ignore __tablename__ = "model" @@ -51,7 +57,7 @@ class ItemAdd(web.View, UnitAddMixin): view.sa_add() -def test_delete_stmt(mocked_request: Request, base_model: orm.Mapper) -> None: +def test_delete_stmt(mocked_request: Request, base_model: orm.Mapper[Any]) -> None: class Model(base_model): # type: ignore __tablename__ = "model" @@ -64,7 +70,7 @@ class ItemDelete(web.View, UnitDeleteMixin): view.get_delete_stmt() -def test_edit_stmt(mocked_request: Request, base_model: orm.Mapper) -> None: +def test_edit_stmt(mocked_request: Request, base_model: orm.Mapper[Any]) -> None: class Model(base_model): # type: ignore __tablename__ = "model" @@ -77,7 +83,7 @@ class InstanceEdit(web.View, UnitEditMixin): view.get_update_stmt() -def test_view_stmt(mocked_request: Request, base_model: orm.Mapper) -> None: +def test_view_stmt(mocked_request: Request, base_model: orm.Mapper[Any]) -> None: class Model(base_model): # type: ignore __tablename__ = "model" @@ -93,7 +99,7 @@ class InstanceView(web.View, UnitViewMixin): async def test_offset_pagination( middlewared_app: web.Application, session: AsyncSession, - base_model: orm.Mapper, + base_model: orm.Mapper[Any], ) -> None: class Model(base_model): # type: ignore __tablename__ = "model" @@ -143,7 +149,7 @@ class OffsetPaginationHandler(web.View, OffsetPaginationMixin): def test_list_add( mocked_request: Request, session: AsyncSession, - base_model: orm.Mapper, + base_model: orm.Mapper[Any], ) -> None: class Model(base_model): # type: ignore __tablename__ = "model"