Skip to content

Commit 077b10e

Browse files
authored
Merge pull request #978 from tisnik/lcore-1051-optional-type-in-sources
LCORE-1051: Updated Optional type in LCORE sources
2 parents 3ac487c + 241b56b commit 077b10e

18 files changed

Lines changed: 81 additions & 69 deletions

src/a2a_storage/context_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Abstract base class for A2A context-to-conversation mapping storage."""
22

33
from abc import ABC, abstractmethod
4+
from typing import Optional
45

56

67
class A2AContextStore(ABC):
@@ -14,7 +15,7 @@ class A2AContextStore(ABC):
1415
"""
1516

1617
@abstractmethod
17-
async def get(self, context_id: str) -> str | None:
18+
async def get(self, context_id: str) -> Optional[str]:
1819
"""Retrieve the conversation ID for an A2A context.
1920
2021
Args:

src/a2a_storage/in_memory_context_store.py

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

33
import asyncio
44
import logging
5+
from typing import Optional
56

67
from a2a_storage.context_store import A2AContextStore
78

@@ -26,7 +27,7 @@ def __init__(self) -> None:
2627
self._lock = asyncio.Lock()
2728
self._initialized = True
2829

29-
async def get(self, context_id: str) -> str | None:
30+
async def get(self, context_id: str) -> Optional[str]:
3031
"""Retrieve the conversation ID for an A2A context.
3132
3233
Args:

src/a2a_storage/postgres_context_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""PostgreSQL implementation of A2A context store."""
22

33
import logging
4+
from typing import Optional
45

56
from sqlalchemy import Column, String, Table, MetaData, select, delete
67
from sqlalchemy.dialects.postgresql import insert as pg_insert
@@ -66,7 +67,7 @@ async def _ensure_initialized(self) -> None:
6667
if not self._initialized:
6768
await self.initialize()
6869

69-
async def get(self, context_id: str) -> str | None:
70+
async def get(self, context_id: str) -> Optional[str]:
7071
"""Retrieve the conversation ID for an A2A context.
7172
7273
Args:

src/a2a_storage/sqlite_context_store.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""SQLite implementation of A2A context store."""
22

33
import logging
4+
from typing import Optional
45

56
from sqlalchemy import Column, String, Table, MetaData, select, delete
67
from sqlalchemy.ext.asyncio import AsyncEngine, async_sessionmaker
@@ -65,7 +66,7 @@ async def _ensure_initialized(self) -> None:
6566
if not self._initialized:
6667
await self.initialize()
6768

68-
async def get(self, context_id: str) -> str | None:
69+
async def get(self, context_id: str) -> Optional[str]:
6970
"""Retrieve the conversation ID for an A2A context.
7071
7172
Args:

src/a2a_storage/storage_factory.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
from urllib.parse import quote_plus
5+
from typing import Optional
56

67
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
78

@@ -24,9 +25,9 @@ class A2AStorageFactory:
2425
creates database-backed stores that share state across workers.
2526
"""
2627

27-
_engine: AsyncEngine | None = None
28-
_task_store: TaskStore | None = None
29-
_context_store: A2AContextStore | None = None
28+
_engine: Optional[AsyncEngine] = None
29+
_task_store: Optional[TaskStore] = None
30+
_context_store: Optional[A2AContextStore] = None
3031

3132
@classmethod
3233
async def create_task_store(cls, config: A2AStateConfiguration) -> TaskStore:

src/app/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Database engine management."""
22

33
from pathlib import Path
4-
from typing import Any
4+
from typing import Any, Optional
55

66
from sqlalchemy import create_engine, text
77
from sqlalchemy.engine.base import Engine
@@ -14,8 +14,8 @@
1414
logger = get_logger(__name__)
1515

1616
# pylint: disable=invalid-name
17-
engine: Engine | None = None
18-
session_local: sessionmaker | None = None
17+
engine: Optional[Engine] = None
18+
session_local: Optional[sessionmaker] = None
1919

2020

2121
def get_engine() -> Engine:

src/authorization/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import logging
44
from functools import lru_cache, wraps
5-
from typing import Any, Callable, Tuple
5+
from typing import Any, Callable, Optional, Tuple
66

77
from fastapi import HTTPException
88
from starlette.requests import Request
@@ -107,7 +107,7 @@ async def _perform_authorization_check(
107107

108108
authorized_actions = access_resolver.get_actions(user_roles)
109109

110-
req: Request | None = None
110+
req: Optional[Request] = None
111111
if "request" in kwargs and isinstance(kwargs["request"], Request):
112112
req = kwargs["request"]
113113
else:

src/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def token_usage_history(self) -> Optional[TokenUsageHistory]:
324324
token history is disabled, returns None.
325325
326326
Returns:
327-
TokenUsageHistory | None: The cached TokenUsageHistory instance
327+
Optional[TokenUsageHistory]: The cached TokenUsageHistory instance
328328
when enabled, otherwise `None`.
329329
330330
Raises:

src/models/cache_entry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Model for conversation history cache entry."""
22

3+
from typing import Optional
34
from pydantic import BaseModel
45
from models.responses import ReferencedDocument
56

@@ -21,4 +22,4 @@ class CacheEntry(BaseModel):
2122
model: str
2223
started_at: str
2324
completed_at: str
24-
referenced_documents: list[ReferencedDocument] | None = None
25+
referenced_documents: Optional[list[ReferencedDocument]] = None

src/models/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ def check_default_model_and_provider(self) -> Self:
11781178
class ConversationHistoryConfiguration(ConfigurationBase):
11791179
"""Conversation history configuration."""
11801180

1181-
type: Literal["noop", "memory", "sqlite", "postgres"] | None = Field(
1181+
type: Optional[Literal["noop", "memory", "sqlite", "postgres"]] = Field(
11821182
None,
11831183
title="Conversation history database type",
11841184
description="Type of database where the conversation history is to be stored.",
@@ -1298,7 +1298,7 @@ def storage_type(self) -> Literal["memory", "sqlite", "postgres"]:
12981298
@property
12991299
def config(
13001300
self,
1301-
) -> SQLiteDatabaseConfiguration | PostgreSQLDatabaseConfiguration | None:
1301+
) -> Optional[SQLiteDatabaseConfiguration | PostgreSQLDatabaseConfiguration]:
13021302
"""Return the active storage configuration, or None for memory storage."""
13031303
if self.sqlite is not None:
13041304
return self.sqlite

0 commit comments

Comments
 (0)