diff --git a/pyproject.toml b/pyproject.toml index d32d3af10..758208691 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -223,7 +223,7 @@ disable = ["R0801"] extend-exclude = ["tests/profiles/syntax_error.py"] [tool.ruff.lint] -extend-select = ["TID251", "UP006", "UP007", "UP035", "RUF100"] +extend-select = ["TID251", "UP006", "UP007", "UP017", "UP035", "RUF100"] [tool.ruff.lint.flake8-tidy-imports.banned-api] unittest = { msg = "use pytest instead of unittest" } diff --git a/src/app/endpoints/a2a.py b/src/app/endpoints/a2a.py index c09a857ee..a00ece91e 100644 --- a/src/app/endpoints/a2a.py +++ b/src/app/endpoints/a2a.py @@ -4,7 +4,7 @@ import json import uuid from collections.abc import Mapping, AsyncIterator, MutableMapping -from datetime import datetime, timezone +from datetime import datetime, UTC from typing import Annotated, Any, Optional from a2a.server.agent_execution import AgentExecutor, RequestContext @@ -381,7 +381,7 @@ async def _process_task_streaming( # pylint: disable=too-many-locals task_id=task_id, status=TaskStatus( state=TaskState.working, - timestamp=datetime.now(timezone.utc).isoformat(), + timestamp=datetime.now(UTC).isoformat(), ), context_id=context_id, final=False, @@ -403,14 +403,14 @@ async def _process_task_streaming( # pylint: disable=too-many-locals if aggregator.task_state == TaskState.working: await task_updater.update_status( TaskState.completed, - timestamp=datetime.now(timezone.utc).isoformat(), + timestamp=datetime.now(UTC).isoformat(), final=True, ) else: await task_updater.update_status( aggregator.task_state, message=aggregator.task_status_message, - timestamp=datetime.now(timezone.utc).isoformat(), + timestamp=datetime.now(UTC).isoformat(), final=True, ) @@ -459,7 +459,7 @@ async def _convert_stream_to_events( # pylint: disable=too-many-branches,too-ma context_id=context_id, task_id=task_id, ), - timestamp=datetime.now(timezone.utc).isoformat(), + timestamp=datetime.now(UTC).isoformat(), ), context_id=context_id, final=False, @@ -477,7 +477,7 @@ async def _convert_stream_to_events( # pylint: disable=too-many-branches,too-ma context_id=context_id, task_id=task_id, ), - timestamp=datetime.now(timezone.utc).isoformat(), + timestamp=datetime.now(UTC).isoformat(), ), context_id=context_id, final=False, @@ -495,7 +495,7 @@ async def _convert_stream_to_events( # pylint: disable=too-many-branches,too-ma context_id=context_id, task_id=task_id, ), - timestamp=datetime.now(timezone.utc).isoformat(), + timestamp=datetime.now(UTC).isoformat(), ), context_id=context_id, final=False, @@ -891,5 +891,5 @@ async def a2a_health_check() -> dict[str, str]: "service": "lightspeed-a2a", "version": __version__, "a2a_sdk_version": "0.3.4", - "timestamp": datetime.now(timezone.utc).isoformat(), + "timestamp": datetime.now(UTC).isoformat(), } diff --git a/src/app/endpoints/query.py b/src/app/endpoints/query.py index 2a0f5faf4..fd123bd21 100644 --- a/src/app/endpoints/query.py +++ b/src/app/endpoints/query.py @@ -237,9 +237,7 @@ async def query_endpoint_handler( quota_limiters=configuration.quota_limiters, user_id=user_id ) - completed_at = datetime.datetime.now(datetime.timezone.utc).strftime( - "%Y-%m-%dT%H:%M:%SZ" - ) + completed_at = datetime.datetime.now(datetime.UTC).strftime("%Y-%m-%dT%H:%M:%SZ") conversation_id = normalize_conversation_id(responses_params.conversation) logger.info("Storing query results") diff --git a/tests/unit/app/endpoints/test_conversations_v2.py b/tests/unit/app/endpoints/test_conversations_v2.py index 8e8787809..0d1c76ab9 100644 --- a/tests/unit/app/endpoints/test_conversations_v2.py +++ b/tests/unit/app/endpoints/test_conversations_v2.py @@ -2,7 +2,7 @@ """Unit tests for the /conversations REST API endpoints.""" -from datetime import datetime, timezone +from datetime import datetime, UTC from typing import Any, cast import pytest @@ -361,9 +361,7 @@ async def test_successful_retrieval( mocker.patch("app.endpoints.conversations_v2.configuration", mock_configuration) timestamp_str = "2024-01-01T00:00:00Z" - timestamp_dt = datetime.fromisoformat(timestamp_str).replace( - tzinfo=timezone.utc - ) + timestamp_dt = datetime.fromisoformat(timestamp_str).replace(tzinfo=UTC) timestamp = timestamp_dt.timestamp() mock_configuration.conversation_cache.list.return_value = [