Skip to content

Commit 4a51d92

Browse files
authored
Merge pull request #2887 from tisnik/lcore-4620-enforce-d413-rule-for-sources
LCORE-4620: Enforce D413 rule for sources
2 parents c742980 + 8b87550 commit 4a51d92

166 files changed

Lines changed: 915 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ line-length = 88
257257
extend-exclude = ["tests/profiles/syntax_error.py"]
258258

259259
[tool.ruff.lint]
260-
extend-select = ["C", "FA", "FLY", "I", "ISC", "TID251", "UP006", "UP007", "UP008", "UP010", "UP012", "UP017", "UP024", "UP035", "UP040", "UP041", "RUF100", "B009", "B010", "B011", "BLE", "DTZ005", "D202", "PLR1733", "RUF022", "PLW1510", "TC004", "PIE790", "PERF402", "FURB129", "RET501", "LOG"]
260+
extend-select = ["C", "FA", "FLY", "I", "ISC", "TID251", "UP006", "UP007", "UP008", "UP010", "UP012", "UP017", "UP024", "UP035", "UP040", "UP041", "RUF100", "B009", "B010", "B011", "BLE", "DTZ005", "D202", "PLR1733", "RUF022", "PLW1510", "TC004", "PIE790", "PERF402", "FURB129", "RET501", "LOG", "D413"]
261261
ignore = ["UP047", "UP045", "S", "C901", "RUF", "SIM", "B017", "TRY004", "TRY201", "TRY203", "TRY401", "B008", "EXE001", "G201", "PYI034", "PYI064"]
262262

263263
[tool.ruff.lint.flake8-tidy-imports.banned-api]

‎src/a2a_storage/context_store.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ async def get(self, context_id: str) -> Optional[str]:
2323
2424
Returns:
2525
The OGX conversation ID, or None if not found.
26+
2627
"""
2728

2829
@abstractmethod
@@ -32,6 +33,7 @@ async def set(self, context_id: str, conversation_id: str) -> None:
3233
Args:
3334
context_id: The A2A context ID.
3435
conversation_id: The OGX conversation ID.
36+
3537
"""
3638

3739
@abstractmethod
@@ -40,6 +42,7 @@ async def delete(self, context_id: str) -> None:
4042
4143
Args:
4244
context_id: The A2A context ID to delete.
45+
4346
"""
4447

4548
@abstractmethod
@@ -55,4 +58,5 @@ def ready(self) -> bool:
5558
5659
Returns:
5760
True if the store is initialized and ready, False otherwise.
61+
5862
"""

‎src/a2a_storage/in_memory_context_store.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async def get(self, context_id: str) -> Optional[str]:
3535
3636
Returns:
3737
The OGX conversation ID, or None if not found.
38+
3839
"""
3940
async with self._lock:
4041
conversation_id = self._contexts.get(context_id)
@@ -52,6 +53,7 @@ async def set(self, context_id: str, conversation_id: str) -> None:
5253
Args:
5354
context_id: The A2A context ID.
5455
conversation_id: The OGX conversation ID.
56+
5557
"""
5658
async with self._lock:
5759
self._contexts[context_id] = conversation_id
@@ -66,6 +68,7 @@ async def delete(self, context_id: str) -> None:
6668
6769
Args:
6870
context_id: The A2A context ID to delete.
71+
6972
"""
7073
async with self._lock:
7174
if context_id in self._contexts:
@@ -89,5 +92,6 @@ def ready(self) -> bool:
8992
9093
Returns:
9194
True, as in-memory store is always ready after construction.
95+
9296
"""
9397
return self._initialized

‎src/a2a_storage/postgres_context_store.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
Args:
4444
engine: SQLAlchemy async engine connected to the PostgreSQL database.
4545
create_table: If True, create the table on initialization.
46+
4647
"""
4748
logger.debug("Initializing PostgresA2AContextStore")
4849
self._engine = engine
@@ -75,6 +76,7 @@ async def get(self, context_id: str) -> Optional[str]:
7576
7677
Returns:
7778
The OGX conversation ID, or None if not found.
79+
7880
"""
7981
await self._ensure_initialized()
8082

@@ -99,6 +101,7 @@ async def set(self, context_id: str, conversation_id: str) -> None:
99101
Args:
100102
context_id: The A2A context ID.
101103
conversation_id: The OGX conversation ID.
104+
102105
"""
103106
await self._ensure_initialized()
104107

@@ -124,6 +127,7 @@ async def delete(self, context_id: str) -> None:
124127
125128
Args:
126129
context_id: The A2A context ID to delete.
130+
127131
"""
128132
await self._ensure_initialized()
129133

@@ -139,5 +143,6 @@ def ready(self) -> bool:
139143
140144
Returns:
141145
True if the store is initialized, False otherwise.
146+
142147
"""
143148
return self._initialized

‎src/a2a_storage/sqlite_context_store.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(
4242
Args:
4343
engine: SQLAlchemy async engine connected to the SQLite database.
4444
create_table: If True, create the table on initialization.
45+
4546
"""
4647
logger.debug("Initializing SQLiteA2AContextStore")
4748
self._engine = engine
@@ -74,6 +75,7 @@ async def get(self, context_id: str) -> Optional[str]:
7475
7576
Returns:
7677
The OGX conversation ID, or None if not found.
78+
7779
"""
7880
await self._ensure_initialized()
7981

@@ -98,6 +100,7 @@ async def set(self, context_id: str, conversation_id: str) -> None:
98100
Args:
99101
context_id: The A2A context ID.
100102
conversation_id: The OGX conversation ID.
103+
101104
"""
102105
await self._ensure_initialized()
103106

@@ -125,6 +128,7 @@ async def delete(self, context_id: str) -> None:
125128
126129
Args:
127130
context_id: The A2A context ID to delete.
131+
128132
"""
129133
await self._ensure_initialized()
130134

@@ -140,5 +144,6 @@ def ready(self) -> bool:
140144
141145
Returns:
142146
True if the store is initialized, False otherwise.
147+
143148
"""
144149
return self._initialized

‎src/a2a_storage/storage_factory.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async def create_task_store(cls, config: A2AStateConfiguration) -> TaskStore:
3838
3939
Returns:
4040
TaskStore implementation (InMemoryTaskStore or DatabaseTaskStore).
41+
4142
"""
4243
if cls._task_store is not None:
4344
return cls._task_store
@@ -86,6 +87,7 @@ async def create_context_store(
8687
8788
Returns:
8889
A2AContextStore implementation.
90+
8991
"""
9092
if cls._context_store is not None:
9193
return cls._context_store
@@ -131,6 +133,7 @@ async def _get_or_create_engine(cls, config: A2AStateConfiguration) -> AsyncEngi
131133
132134
Returns:
133135
SQLAlchemy AsyncEngine.
136+
134137
"""
135138
if cls._engine is not None:
136139
return cls._engine

‎src/app/database.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def get_engine() -> Engine:
2929
Raises:
3030
RuntimeError: If the database engine has not been initialized; call
3131
initialize_database() first.
32+
3233
"""
3334
if engine is None:
3435
raise RuntimeError(
@@ -45,6 +46,7 @@ def create_tables() -> None:
4546
Raises:
4647
RuntimeError: If the global database engine is not initialized (call
4748
initialize_database() first).
49+
4850
"""
4951
Base.metadata.create_all(get_engine())
5052

@@ -60,6 +62,7 @@ def get_session() -> Session:
6062
Raises:
6163
RuntimeError: If the database has not been initialized; call
6264
initialize_database() first.
65+
6366
"""
6467
if session_local is None:
6568
raise RuntimeError(
@@ -85,6 +88,7 @@ def _create_sqlite_engine(config: SQLiteDatabaseConfiguration, **kwargs: Any) ->
8588
------
8689
FileNotFoundError: If the parent directory of `config.db_path` does not exist.
8790
RuntimeError: If engine creation fails.
91+
8892
"""
8993
if not Path(config.db_path).parent.exists():
9094
raise FileNotFoundError(
@@ -122,6 +126,7 @@ def _create_postgres_engine(
122126
Raises:
123127
------
124128
RuntimeError: If engine creation fails or if creating the specified schema fails.
129+
125130
"""
126131
postgres_url = (
127132
f"postgresql://{config.user}:{config.password.get_secret_value()}@"

‎src/app/endpoints/a2a.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ async def _get_task_store() -> TaskStore:
104104
105105
Returns:
106106
TaskStore instance based on configuration.
107+
107108
"""
108109
global _TASK_STORE # pylint: disable=global-statement
109110
if _TASK_STORE is None:
@@ -116,6 +117,7 @@ async def _get_context_store() -> A2AContextStore:
116117
117118
Returns:
118119
A2AContextStore instance based on configuration.
120+
119121
"""
120122
global _CONTEXT_STORE # pylint: disable=global-statement
121123
if _CONTEXT_STORE is None:
@@ -141,6 +143,7 @@ def _build_a2a_parts_from_agent_result(
141143
142144
Returns:
143145
List of A2A Part objects for the final artifact.
146+
144147
"""
145148
if run_result is not None:
146149
final_text = run_result.response.text or "".join(accumulated_text)
@@ -157,6 +160,7 @@ def _record_model_span(span: trace.Span, model_id: str) -> None:
157160
Parameters:
158161
span: The active OpenTelemetry span.
159162
model_id: Full model identifier in "provider/model" format.
163+
160164
"""
161165
provider_id, bare_model_id = extract_provider_and_model_from_model_id(model_id)
162166
set_span_attributes(
@@ -183,6 +187,7 @@ def _record_execution_span(
183187
run_result: Completed agent run result, or None.
184188
compacted: Whether the turn used compacted conversation context.
185189
inference_time: Request processing duration in seconds.
190+
186191
"""
187192
if tool_call_names:
188193
set_span_attributes(
@@ -234,6 +239,7 @@ async def _persist_compacted_a2a_turn(
234239
the request was served in compacted mode.
235240
agent: The pydantic-ai agent whose model captured the output items.
236241
task_id: A2A task identifier, used for error reporting.
242+
237243
"""
238244
if not compaction.compacted or compaction.original_input is None:
239245
return
@@ -275,6 +281,7 @@ def process_event(
275281
276282
Args:
277283
event: The event to process
284+
278285
"""
279286
if isinstance(event, TaskStatusUpdateEvent):
280287
if event.status.state == TaskState.failed:
@@ -335,6 +342,7 @@ def __init__(
335342
auth_token: Authentication token for the request
336343
mcp_headers: MCP headers for context propagation
337344
request_headers: Incoming HTTP request headers for allowlist propagation
345+
338346
"""
339347
self.auth_token: str = auth_token
340348
self.mcp_headers: McpHeaders = mcp_headers or {}
@@ -352,6 +360,7 @@ async def execute(
352360
Args:
353361
context: The request context containing user input and metadata
354362
event_queue: Queue for sending response events
363+
355364
"""
356365
if not context.message:
357366
raise ValueError("A2A request must have a message")
@@ -406,6 +415,7 @@ async def _process_task_streaming( # pylint: disable=too-many-locals,too-many-s
406415
task_updater: Task updater for sending events
407416
task_id: The task ID to use for this execution
408417
context_id: The context ID to use for this execution
418+
409419
"""
410420
if not task_id or not context_id:
411421
raise ValueError("Task ID and Context ID are required")
@@ -628,6 +638,7 @@ async def _convert_stream_to_events(
628638
629639
Yields:
630640
A2A events (TaskStatusUpdateEvent or TaskArtifactUpdateEvent)
641+
631642
"""
632643
if not task_id or not context_id:
633644
raise ValueError("Task ID and Context ID are required")
@@ -686,6 +697,7 @@ def _dispatch_agent_event( # pylint: disable=too-many-arguments,too-many-positi
686697
687698
Returns:
688699
A2A TaskStatusUpdateEvent, or None if the event is not mapped.
700+
689701
"""
690702
_ = artifact_id
691703

@@ -752,6 +764,7 @@ def _text_status_event(
752764
753765
Returns:
754766
TaskStatusUpdateEvent with the text delta.
767+
755768
"""
756769
return TaskStatusUpdateEvent(
757770
task_id=task_id,
@@ -781,6 +794,7 @@ async def cancel(
781794
782795
Raises:
783796
NotImplementedError: Task cancellation is not currently supported
797+
784798
"""
785799
logger.info("Cancellation requested but not currently supported")
786800
raise NotImplementedError("Task cancellation not currently supported")
@@ -798,6 +812,7 @@ def get_lightspeed_agent_card() -> AgentCard:
798812
799813
Returns:
800814
AgentCard: The agent card describing Lightspeed's capabilities.
815+
801816
"""
802817
# Get base URL from configuration or construct it
803818
service_config = configuration.service_configuration
@@ -922,6 +937,7 @@ async def _create_a2a_app(
922937
923938
Returns:
924939
A2A Starlette ASGI application
940+
925941
"""
926942
agent_executor = A2AAgentExecutor(
927943
auth_token=auth_token,
@@ -1061,6 +1077,7 @@ async def _handle_a2a_jsonrpc( # pylint: disable=too-many-locals,too-many-state
10611077
10621078
Returns:
10631079
JSON-RPC response or streaming response
1080+
10641081
"""
10651082
logger.debug("A2A endpoint called: %s %s", request.method, request.url.path)
10661083

‎src/app/endpoints/conversations_v1.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ async def get_conversation_endpoint_handler( # pylint: disable=too-many-locals,
234234
Returns:
235235
ConversationResponse: Structured response containing the conversation
236236
ID and simplified chat history
237+
237238
"""
238239
with tracer.start_as_current_span("conversations_v1.get") as span:
239240
check_configuration_loaded(configuration)
@@ -356,6 +357,7 @@ async def delete_conversation_endpoint_handler(
356357
357358
Returns:
358359
ConversationDeleteResponse: Response indicating the result of the deletion operation
360+
359361
"""
360362
with tracer.start_as_current_span("conversations_v1.delete") as span:
361363
check_configuration_loaded(configuration)
@@ -477,6 +479,7 @@ async def update_conversation_endpoint_handler( # pylint: disable=too-many-stat
477479
478480
Returns:
479481
ConversationUpdateResponse: Response indicating the result of the update operation
482+
480483
"""
481484
with tracer.start_as_current_span("conversations_v1.update") as span:
482485
check_configuration_loaded(configuration)

‎src/app/endpoints/conversations_v2.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ def build_conversation_turn_from_cache_entry(entry: CacheEntry) -> ConversationT
275275
276276
Returns:
277277
ConversationTurn object with messages, tool_calls, tool_results, and timestamps
278+
278279
"""
279280
# Create Message objects for user and assistant
280281
messages = [

0 commit comments

Comments
 (0)