fix: ruff warnings

This commit is contained in:
2026-07-28 13:55:31 +02:00
committed by d3vyce
parent a407677be0
commit fd83a7142d
36 changed files with 255 additions and 138 deletions
+1 -1
View File
@@ -22,7 +22,6 @@ __all__ = [
"AsyncCrud",
"CrudFactory",
"FacetFieldType",
"get_searchable_fields",
"InvalidFacetFilterError",
"InvalidSearchColumnError",
"JoinType",
@@ -34,4 +33,5 @@ __all__ = [
"SearchConfig",
"SearchFieldType",
"UnsupportedFacetTypeError",
"get_searchable_fields",
]
+4 -5
View File
@@ -1580,11 +1580,10 @@ class AsyncCrud(Generic[ModelType]):
# prev_cursor: points before the first item in ascending order
prev_cursor: str | None = None
if direction is _CursorDirection.NEXT and cursor is not None and items_page:
prev_cursor = _encode_cursor(
getattr(items_page[0], cursor_col_name), direction=_CursorDirection.PREV
)
elif direction is _CursorDirection.PREV and has_more and items_page:
if items_page and (
(direction is _CursorDirection.NEXT and cursor is not None)
or (direction is _CursorDirection.PREV and has_more)
):
prev_cursor = _encode_cursor(
getattr(items_page[0], cursor_col_name), direction=_CursorDirection.PREV
)
+1 -1
View File
@@ -386,7 +386,7 @@ def build_filter_by(
enum_class = col_type.enum_class
if enum_class is not None:
def _coerce_enum(v: Any) -> Any:
def _coerce_enum(v: Any, enum_class: Any = enum_class) -> Any:
if isinstance(v, enum_class):
return v
return enum_class[v] # lookup by name: "PENDING", "RED"
+2 -3
View File
@@ -212,9 +212,8 @@ class Database:
@asynccontextmanager
async def _composed(app_: Any) -> AsyncGenerator[None, None]:
async with self.lifespan(app_):
async with inner_lifespan(app_):
yield
async with self.lifespan(app_), inner_lifespan(app_):
yield
app.router.lifespan_context = _composed
+1 -3
View File
@@ -1,6 +1,6 @@
"""Many-to-Many association-table helpers (direct, without loading collections)."""
from typing import Any, TypeVar, cast
from typing import Any, cast
from sqlalchemy import ColumnElement, Table, delete, tuple_
from sqlalchemy.dialects.postgresql import insert as pg_insert
@@ -8,8 +8,6 @@ from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import DeclarativeBase, QueryableAttribute
from sqlalchemy.orm.relationships import RelationshipProperty
_M = TypeVar("_M", bound=DeclarativeBase)
def _m2m_prop(rel_attr: QueryableAttribute) -> tuple[RelationshipProperty, Table]: # type: ignore[type-arg]
"""Return the validated M2M RelationshipProperty and its secondary table.
+25 -33
View File
@@ -60,7 +60,7 @@ def PathDependency(
name = (
param_name
if param_name is not None
else "{}_{}".format(model.__name__.lower(), field.key)
else f"{model.__name__.lower()}_{field.key}"
)
python_type = field.type.python_type
@@ -70,22 +70,18 @@ def PathDependency(
value = kwargs[name]
return await crud.get(session, filters=[field == value])
setattr(
dependency,
"__signature__",
inspect.Signature(
parameters=[
inspect.Parameter(
name, inspect.Parameter.KEYWORD_ONLY, annotation=python_type
),
inspect.Parameter(
"session",
inspect.Parameter.KEYWORD_ONLY,
annotation=AsyncSession,
default=Depends(session_callable),
),
]
),
dependency.__signature__ = inspect.Signature( # ty:ignore[unresolved-attribute]
parameters=[
inspect.Parameter(
name, inspect.Parameter.KEYWORD_ONLY, annotation=python_type
),
inspect.Parameter(
"session",
inspect.Parameter.KEYWORD_ONLY,
annotation=AsyncSession,
default=Depends(session_callable),
),
]
)
return cast(ModelType, Depends(cast(Callable[..., ModelType], dependency)))
@@ -134,22 +130,18 @@ def BodyDependency(
value = kwargs[body_field]
return await crud.get(session, filters=[field == value])
setattr(
dependency,
"__signature__",
inspect.Signature(
parameters=[
inspect.Parameter(
body_field, inspect.Parameter.KEYWORD_ONLY, annotation=python_type
),
inspect.Parameter(
"session",
inspect.Parameter.KEYWORD_ONLY,
annotation=AsyncSession,
default=Depends(session_callable),
),
]
),
dependency.__signature__ = inspect.Signature( # ty:ignore[unresolved-attribute]
parameters=[
inspect.Parameter(
body_field, inspect.Parameter.KEYWORD_ONLY, annotation=python_type
),
inspect.Parameter(
"session",
inspect.Parameter.KEYWORD_ONLY,
annotation=AsyncSession,
default=Depends(session_callable),
),
]
)
return cast(ModelType, Depends(cast(Callable[..., ModelType], dependency)))
+2 -2
View File
@@ -23,8 +23,6 @@ __all__ = [
"ApiException",
"ConflictError",
"ForbiddenError",
"generate_error_responses",
"init_exceptions_handlers",
"InvalidFacetFilterError",
"InvalidOrderFieldError",
"InvalidSearchColumnError",
@@ -34,4 +32,6 @@ __all__ = [
"PoolExhaustedError",
"UnauthorizedError",
"UnsupportedFacetTypeError",
"generate_error_responses",
"init_exceptions_handlers",
]
+25 -26
View File
@@ -146,35 +146,34 @@ def _patched_openapi(
for path_data in openapi_schema.get("paths", {}).values():
for operation in path_data.values():
if isinstance(operation, dict) and "responses" in operation:
if "422" in operation["responses"]:
operation["responses"]["422"] = {
"description": "Validation Error",
"content": {
"application/json": {
"examples": {
"VAL-422": {
"summary": "Validation Error",
"value": {
"data": {
"errors": [
{
"field": "field_name",
"message": "value is not valid",
"type": "value_error",
}
]
},
"status": ResponseStatus.FAIL.value,
"message": "Validation Error",
"description": "1 validation error(s) detected",
"error_code": "VAL-422",
if isinstance(operation, dict) and "422" in operation.get("responses", {}):
operation["responses"]["422"] = {
"description": "Validation Error",
"content": {
"application/json": {
"examples": {
"VAL-422": {
"summary": "Validation Error",
"value": {
"data": {
"errors": [
{
"field": "field_name",
"message": "value is not valid",
"type": "value_error",
}
]
},
}
"status": ResponseStatus.FAIL.value,
"message": "Validation Error",
"description": "1 validation error(s) detected",
"error_code": "VAL-422",
},
}
}
},
}
}
},
}
app.openapi_schema = openapi_schema
return app.openapi_schema
+3 -3
View File
@@ -3,19 +3,19 @@
from .columns import (
CreatedAtMixin,
TimestampMixin,
UpdatedAtMixin,
UUIDMixin,
UUIDv7Mixin,
UpdatedAtMixin,
)
from .watched import EventSession, ModelEvent, listens_for
__all__ = [
"CreatedAtMixin",
"EventSession",
"ModelEvent",
"TimestampMixin",
"UUIDMixin",
"UUIDv7Mixin",
"CreatedAtMixin",
"UpdatedAtMixin",
"TimestampMixin",
"listens_for",
]
+1 -1
View File
@@ -206,7 +206,7 @@ async def _batch_reload(
class EventSession(AsyncSession):
"""AsyncSession subclass that dispatches lifecycle callbacks after commit."""
async def commit(self) -> None: # noqa: C901
async def commit(self) -> None:
await super().commit()
creates: list[Any] = self.info.pop(_SESSION_CREATES, [])
+4 -4
View File
@@ -2,7 +2,7 @@
import math
from enum import Enum
from typing import Annotated, Any, ClassVar, Generic, Literal, TypeVar, Union
from typing import Annotated, Any, ClassVar, Generic, Literal, TypeVar
from pydantic import BaseModel, ConfigDict, Field, computed_field
@@ -10,11 +10,11 @@ from .types import DataT
__all__ = [
"ApiError",
"CursorPagination",
"CursorPaginatedResponse",
"CursorPagination",
"ErrorResponse",
"OffsetPagination",
"OffsetPaginatedResponse",
"OffsetPagination",
"PaginatedResponse",
"PaginationType",
"PydanticBase",
@@ -174,7 +174,7 @@ class PaginatedResponse(BaseResponse, Generic[DataT]):
cached = cls._discriminated_union_cache.get(item)
if cached is None:
cached = Annotated[
Union[CursorPaginatedResponse[item], OffsetPaginatedResponse[item]], # ty:ignore[invalid-type-form]
CursorPaginatedResponse[item] | OffsetPaginatedResponse[item], # ty:ignore[invalid-type-form]
Field(discriminator="pagination_type"),
]
cls._discriminated_union_cache[item] = cached