Skip to content

Commit 13236e5

Browse files
committed
fix linting errors
1 parent 8ab33b4 commit 13236e5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/a2a/server/models.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from typing_extensions import override
66
else:
77

8-
def override(func): # noqa: D103
8+
def override(func):
9+
"""Override decorator."""
910
return func
1011

1112

@@ -44,13 +45,20 @@ class PydanticType(TypeDecorator[T], Generic[T]):
4445
cache_ok = True
4546

4647
def __init__(self, pydantic_type: type[T], **kwargs: dict[str, Any]):
48+
"""Initialize the PydanticType.
49+
50+
Args:
51+
pydantic_type: The Pydantic model type to handle.
52+
**kwargs: Additional arguments for TypeDecorator.
53+
"""
4754
self.pydantic_type = pydantic_type
4855
super().__init__(**kwargs)
4956

5057
@override
5158
def process_bind_param(
5259
self, value: T | None, dialect: Dialect
5360
) -> dict[str, Any] | None:
61+
"""Convert Pydantic model to a JSON-serializable dictionary for the database."""
5462
if value is None:
5563
return None
5664
return (
@@ -63,6 +71,7 @@ def process_bind_param(
6371
def process_result_value(
6472
self, value: dict[str, Any] | None, dialect: Dialect
6573
) -> T | None:
74+
"""Convert a JSON-like dictionary from the database back to a Pydantic model."""
6675
if value is None:
6776
return None
6877
return self.pydantic_type.model_validate(value)
@@ -75,13 +84,20 @@ class PydanticListType(TypeDecorator[list[T]], Generic[T]):
7584
cache_ok = True
7685

7786
def __init__(self, pydantic_type: type[T], **kwargs: dict[str, Any]):
87+
"""Initialize the PydanticListType.
88+
89+
Args:
90+
pydantic_type: The Pydantic model type for items in the list.
91+
**kwargs: Additional arguments for TypeDecorator.
92+
"""
7893
self.pydantic_type = pydantic_type
7994
super().__init__(**kwargs)
8095

8196
@override
8297
def process_bind_param(
8398
self, value: list[T] | None, dialect: Dialect
8499
) -> list[dict[str, Any]] | None:
100+
"""Convert a list of Pydantic models to a JSON-serializable list for the DB."""
85101
if value is None:
86102
return None
87103
return [
@@ -95,6 +111,7 @@ def process_bind_param(
95111
def process_result_value(
96112
self, value: list[dict[str, Any]] | None, dialect: Dialect
97113
) -> list[T] | None:
114+
"""Convert a JSON-like list from the DB back to a list of Pydantic models."""
98115
if value is None:
99116
return None
100117
return [self.pydantic_type.model_validate(item) for item in value]
@@ -128,6 +145,7 @@ class TaskMixin:
128145
@declared_attr
129146
@classmethod
130147
def task_metadata(cls) -> Mapped[dict[str, Any] | None]:
148+
"""Define the 'metadata' column, avoiding name conflicts with Pydantic."""
131149
return mapped_column(JSON, nullable=True, name='metadata')
132150

133151
@override

src/a2a/server/tasks/database_task_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
try:
5-
from sqlalchemy import delete, select, update
5+
from sqlalchemy import delete, select
66
from sqlalchemy.ext.asyncio import (
77
AsyncEngine,
88
AsyncSession,

0 commit comments

Comments
 (0)