Skip to content

Commit

Permalink
feat: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Sep 21, 2024
1 parent 6cb1674 commit e1a9bdf
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 117 deletions.
33 changes: 23 additions & 10 deletions litestar/contrib/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004, F401
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -11,15 +12,22 @@
"wrap_sqlalchemy_exception",
)


def __getattr__(attr_name: str) -> object:
if attr_name in __all__:
if attr_name in ("SQLAlchemyAsyncRepository", "SQLAlchemySyncRepository","ModelT"):
module = f"litestar.plugins.sqlalchemy.repository"
from advanced_alchemy.extensions.litestar import repository # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
if attr_name in ("SQLAlchemyAsyncRepository", "SQLAlchemySyncRepository", "ModelT"):
module = "litestar.plugins.sqlalchemy.repository"
from advanced_alchemy.extensions.litestar import ( # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
repository,
)

value = globals()[attr_name] = getattr(repository, attr_name)
elif attr_name == "wrap_sqlalchemy_exception":
module = f"litestar.plugins.sqlalchemy.exceptions"
from advanced_alchemy.extensions.litestar import exceptions # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
module = "litestar.plugins.sqlalchemy.exceptions"
from advanced_alchemy.extensions.litestar import ( # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
exceptions,
)

value = globals()[attr_name] = getattr(exceptions, attr_name)
warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.{attr_name}",
Expand All @@ -29,13 +37,18 @@ def __getattr__(attr_name: str) -> object:
info=f"importing {attr_name} from 'litestar.contrib.sqlalchemy' is deprecated, please "
f"import it from '{module}' instead",
)



return value

raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}")


if TYPE_CHECKING:
from advanced_alchemy.extensions.litestar.repository import SQLAlchemyAsyncRepository, SQLAlchemySyncRepository # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
from advanced_alchemy.extensions.litestar.repository import ModelT # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
from advanced_alchemy.extensions.litestar.exceptions import wrap_sqlalchemy_exception # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
from advanced_alchemy.extensions.litestar.exceptions import ( # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
wrap_sqlalchemy_exception,
)
from advanced_alchemy.extensions.litestar.repository import ( # type: ignore[import-not-found] # pyright: ignore[reportMissingImports]
ModelT,
SQLAlchemyAsyncRepository,
SQLAlchemySyncRepository,
)
1 change: 1 addition & 0 deletions litestar/contrib/sqlalchemy/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Application ORM configuration."""

# ruff: noqa: TCH004
from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
8 changes: 5 additions & 3 deletions litestar/contrib/sqlalchemy/dto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""SQLAlchemy DTO configuration."""

# ruff: noqa: TCH004
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -10,8 +11,6 @@


def __getattr__(attr_name: str) -> object:
from advanced_alchemy.extensions.litestar.dto import SQLAlchemyDTO, SQLAlchemyDTOConfig # pyright: ignore[reportMissingImports]

if attr_name in __all__:
warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.{attr_name}",
Expand All @@ -28,4 +27,7 @@ def __getattr__(attr_name: str) -> object:


if TYPE_CHECKING:
from advanced_alchemy.extensions.litestar.dto import SQLAlchemyDTO, SQLAlchemyDTOConfig # pyright: ignore[reportMissingImports]
from advanced_alchemy.extensions.litestar.dto import ( # pyright: ignore[reportMissingImports]
SQLAlchemyDTO,
SQLAlchemyDTOConfig,
)
30 changes: 17 additions & 13 deletions litestar/contrib/sqlalchemy/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004, F401
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -17,29 +18,30 @@
"SyncSessionConfig",
)


def __getattr__(attr_name: str) -> object:
if attr_name in __all__:


if attr_name in ( "GenericSQLAlchemyConfig", "GenericSessionConfig"):
if attr_name in ("GenericSQLAlchemyConfig", "GenericSessionConfig"):
module = "litestar.plugins.sqlalchemy.config"
from advanced_alchemy.config import ( # pyright: ignore[reportMissingImports]
GenericSessionConfig,
GenericSQLAlchemyConfig,
GenericSQLAlchemyConfig,
)

value = globals()[attr_name] = locals()[attr_name]
else:
module = "litestar.plugins.sqlalchemy"
module = "litestar.plugins.sqlalchemy"
from advanced_alchemy.extensions.litestar import ( # pyright: ignore[reportMissingImports]
AsyncSessionConfig,
EngineConfig,
SQLAlchemyPlugin,
SQLAlchemySerializationPlugin,
SQLAlchemyAsyncConfig,
SQLAlchemyInitPlugin,
SQLAlchemyPlugin,
SQLAlchemySerializationPlugin,
SQLAlchemySyncConfig,
SyncSessionConfig,
)

value = globals()[attr_name] = locals()[attr_name]
warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.plugins.{attr_name}",
Expand All @@ -53,14 +55,16 @@ def __getattr__(attr_name: str) -> object:

raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}")


if TYPE_CHECKING:
from advanced_alchemy.extensions.litestar import (SQLAlchemyPlugin, SQLAlchemySerializationPlugin, AsyncSessionConfig,
EngineConfig,
from advanced_alchemy.config import GenericSessionConfig, GenericSQLAlchemyConfig
from advanced_alchemy.extensions.litestar import (
AsyncSessionConfig,
EngineConfig,
SQLAlchemyAsyncConfig,
SQLAlchemyInitPlugin,
SQLAlchemyPlugin,
SQLAlchemySerializationPlugin,
SQLAlchemySyncConfig,
SyncSessionConfig,)
from advanced_alchemy.config import (
GenericSessionConfig,
GenericSQLAlchemyConfig
SyncSessionConfig,
)
27 changes: 17 additions & 10 deletions litestar/contrib/sqlalchemy/plugins/init/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004, F401
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -15,25 +16,28 @@
"SyncSessionConfig",
)


def __getattr__(attr_name: str) -> object:
if attr_name in __all__:
if attr_name in ( "GenericSQLAlchemyConfig", "GenericSessionConfig"):
module = "litestar.plugins.sqlalchemy.config"
if attr_name in ("GenericSQLAlchemyConfig", "GenericSessionConfig"):
module = "advanced_alchemy.config"
from advanced_alchemy.config import ( # pyright: ignore[reportMissingImports]
GenericSessionConfig,
GenericSQLAlchemyConfig,
GenericSQLAlchemyConfig,
)

value = globals()[attr_name] = locals()[attr_name]
else:
module = "litestar.plugins.sqlalchemy.config"
from advanced_alchemy.extensions.litestar.plugins.init import (
module = "litestar.plugins.sqlalchemy"
from advanced_alchemy.extensions.litestar import (
AsyncSessionConfig,
EngineConfig,
EngineConfig,
SQLAlchemyAsyncConfig,
SQLAlchemyInitPlugin,
SQLAlchemySyncConfig,
SyncSessionConfig,
)
)

value = globals()[attr_name] = locals()[attr_name]
warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.plugins.init.{attr_name}",
Expand All @@ -47,12 +51,15 @@ def __getattr__(attr_name: str) -> object:

raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}")


if TYPE_CHECKING:
from advanced_alchemy.extensions.litestar.plugins.init import (
AsyncSessionConfig,
EngineConfig,
from advanced_alchemy.config import ( # pyright: ignore[reportMissingImports]
GenericSessionConfig,
GenericSQLAlchemyConfig,
)
from advanced_alchemy.extensions.litestar import ( # pyright: ignore[reportMissingImports]
AsyncSessionConfig,
EngineConfig,
SQLAlchemyAsyncConfig,
SQLAlchemyInitPlugin,
SQLAlchemySyncConfig,
Expand Down
21 changes: 16 additions & 5 deletions litestar/contrib/sqlalchemy/plugins/init/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004,F401
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -14,23 +15,29 @@
"SyncSessionConfig",
)


def __getattr__(attr_name: str) -> object:
if attr_name in __all__:
if attr_name in ("GenericSQLAlchemyConfig", "GenericSessionConfig"):
module = "litestar.plugins.sqlalchemy.config"
from advanced_alchemy.config import GenericSQLAlchemyConfig, GenericSessionConfig # pyright: ignore[reportMissingImports]
from advanced_alchemy.config import ( # pyright: ignore[reportMissingImports]
GenericSessionConfig,
GenericSQLAlchemyConfig,
)

value = globals()[attr_name] = locals()[attr_name]
else:
module = "litestar.plugins.sqlalchemy"
from advanced_alchemy.extensions.litestar import ( # pyright: ignore[reportMissingImports]
from advanced_alchemy.extensions.litestar import ( # pyright: ignore[reportMissingImports]
AsyncSessionConfig,
EngineConfig,
SQLAlchemyAsyncConfig,
SQLAlchemySyncConfig,
SyncSessionConfig,
)

value = globals()[attr_name] = locals()[attr_name]

warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.plugins.init.config.{attr_name}",
version="2.11",
Expand All @@ -44,9 +51,13 @@ def __getattr__(attr_name: str) -> object:

raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}")


if TYPE_CHECKING:
from advanced_alchemy.config import GenericSQLAlchemyConfig, GenericSessionConfig # pyright: ignore[reportMissingImports]
from advanced_alchemy.extensions.litestar import ( # pyright: ignore[reportMissingImports]
from advanced_alchemy.config import ( # pyright: ignore[reportMissingImports]
GenericSessionConfig,
GenericSQLAlchemyConfig,
)
from advanced_alchemy.extensions.litestar import ( # pyright: ignore[reportMissingImports]
AsyncSessionConfig,
EngineConfig,
SQLAlchemyAsyncConfig,
Expand Down
24 changes: 8 additions & 16 deletions litestar/contrib/sqlalchemy/plugins/init/config/asyncio.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -16,32 +17,25 @@
def __getattr__(attr_name: str) -> object:
if attr_name in __all__:
if attr_name == "SQLAlchemyAsyncConfig":
from litestar.contrib.sqlalchemy.plugins.init.config.compat import _CreateEngineMixin
from sqlalchemy.ext.asyncio import AsyncEngine
from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import (
SQLAlchemyAsyncConfig as _SQLAlchemyAsyncConfig,
)
from sqlalchemy.ext.asyncio import AsyncEngine

from litestar.contrib.sqlalchemy.plugins.init.config.compat import _CreateEngineMixin

class SQLAlchemyAsyncConfig(_SQLAlchemyAsyncConfig, _CreateEngineMixin[AsyncEngine]): ...

module = "litestar.plugins.sqlalchemy"
value = globals()[attr_name] = SQLAlchemyAsyncConfig
elif attr_name in {"default_before_send_handler", "autocommit_before_send_handler"}:
module = "litestar.plugins.sqlalchemy.plugins.init.config.asyncio"
from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import (
default_before_send_handler,
autocommit_before_send_handler,
)

value = globals()[attr_name] = locals()[attr_name]
else:
module = "litestar.plugins.sqlalchemy"
from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import (
AlembicAsyncConfig,
AsyncSessionConfig,
)

value = globals()[attr_name] = autocommit_before_send_handler
value = globals()[attr_name] = locals()[attr_name]

warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.plugins.init.config.asyncio.{attr_name}",
Expand All @@ -58,14 +52,12 @@ class SQLAlchemyAsyncConfig(_SQLAlchemyAsyncConfig, _CreateEngineMixin[AsyncEngi


if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncEngine
from litestar.contrib.sqlalchemy.plugins.init.config.compat import _CreateEngineMixin
from advanced_alchemy.extensions.litestar import (
SQLAlchemyAsyncConfig,
AlembicAsyncConfig,
AsyncSessionConfig,
AsyncSessionConfig,
SQLAlchemyAsyncConfig,
)
from advanced_alchemy.extensions.litestar.plugins.init.config.asyncio import (
default_before_send_handler,
autocommit_before_send_handler,
default_before_send_handler,
)
14 changes: 6 additions & 8 deletions litestar/contrib/sqlalchemy/plugins/init/config/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -12,18 +13,14 @@
"GenericAlembicConfig",
)


def __getattr__(attr_name: str) -> object:
if attr_name in __all__:
if attr_name in ("GenericSQLAlchemyConfig", "GenericSessionConfig", "GenericAlembicConfig"):
from advanced_alchemy.config.common import GenericAlembicConfig, GenericSessionConfig, GenericSQLAlchemyConfig
module = 'litestar.plugins.sqlalchemy.config'
module = "litestar.plugins.sqlalchemy.config"
else:
module = 'litestar.plugins.sqlalchemy.plugins.init.config.common'
from advanced_alchemy.extensions.litestar.plugins.init.config.common import (
SESSION_SCOPE_KEY,
SESSION_TERMINUS_ASGI_EVENTS,
)

module = "litestar.plugins.sqlalchemy.plugins.init.config.common"

warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.plugins.init.config.common.{attr_name}",
version="2.11",
Expand All @@ -37,6 +34,7 @@ def __getattr__(attr_name: str) -> object:

raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}")


if TYPE_CHECKING:
from advanced_alchemy.config.common import GenericAlembicConfig, GenericSessionConfig, GenericSQLAlchemyConfig
from advanced_alchemy.extensions.litestar.plugins.init.config.common import (
Expand Down
10 changes: 7 additions & 3 deletions litestar/contrib/sqlalchemy/plugins/init/config/engine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: TCH004
from __future__ import annotations

from typing import TYPE_CHECKING
Expand All @@ -6,11 +7,13 @@

__all__ = ("EngineConfig",)


def __getattr__(attr_name: str) -> object:
if attr_name in __all__:
from advanced_alchemy.extensions.litestar import EngineConfig
module = 'litestar.plugins.sqlalchemy'


module = "litestar.plugins.sqlalchemy"

warn_deprecation(
deprecated_name=f"litestar.contrib.sqlalchemy.plugins.init.config.engine.{attr_name}",
version="2.11",
Expand All @@ -24,5 +27,6 @@ def __getattr__(attr_name: str) -> object:

raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}")


if TYPE_CHECKING:
from advanced_alchemy.extensions.litestar import EngineConfig
from advanced_alchemy.extensions.litestar import EngineConfig
Loading

0 comments on commit e1a9bdf

Please sign in to comment.