mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix mypy errors in storage directory (#6809)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
parent
340c2310d1
commit
cb72a06ca3
@ -15,7 +15,7 @@ class ConversationStore(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
async def save_metadata(self, metadata: ConversationMetadata):
|
||||
async def save_metadata(self, metadata: ConversationMetadata) -> None:
|
||||
"""Store conversation metadata"""
|
||||
|
||||
@abstractmethod
|
||||
|
||||
@ -29,7 +29,7 @@ conversation_metadata_type_adapter = TypeAdapter(ConversationMetadata)
|
||||
class FileConversationStore(ConversationStore):
|
||||
file_store: FileStore
|
||||
|
||||
async def save_metadata(self, metadata: ConversationMetadata):
|
||||
async def save_metadata(self, metadata: ConversationMetadata) -> None:
|
||||
json_str = conversation_metadata_type_adapter.dump_json(metadata)
|
||||
path = self.get_conversation_metadata_filename(metadata.conversation_id)
|
||||
await call_sync_from_async(self.file_store.write, path, json_str)
|
||||
|
||||
@ -29,7 +29,7 @@ class GoogleCloudFileStore(FileStore):
|
||||
blob = self.bucket.blob(path)
|
||||
try:
|
||||
with blob.open('r') as f:
|
||||
return f.read()
|
||||
return str(f.read())
|
||||
except NotFound as err:
|
||||
raise FileNotFoundError(err)
|
||||
|
||||
|
||||
@ -17,7 +17,7 @@ class LocalFileStore(FileStore):
|
||||
path = path[1:]
|
||||
return os.path.join(self.root, path)
|
||||
|
||||
def write(self, path: str, contents: str | bytes):
|
||||
def write(self, path: str, contents: str | bytes) -> None:
|
||||
full_path = self.get_full_path(path)
|
||||
os.makedirs(os.path.dirname(full_path), exist_ok=True)
|
||||
mode = 'w' if isinstance(contents, str) else 'wb'
|
||||
|
||||
@ -46,7 +46,7 @@ class S3FileStore(FileStore):
|
||||
try:
|
||||
response = self.client.get_object(Bucket=self.bucket, Key=path)
|
||||
with response['Body'] as stream:
|
||||
return stream.read().decode('utf-8')
|
||||
return str(stream.read().decode('utf-8'))
|
||||
except botocore.exceptions.ClientError as e:
|
||||
# Catch all S3-related errors
|
||||
if e.response['Error']['Code'] == 'NoSuchBucket':
|
||||
|
||||
@ -25,7 +25,7 @@ class FileSettingsStore(SettingsStore):
|
||||
except FileNotFoundError:
|
||||
return None
|
||||
|
||||
async def store(self, settings: Settings):
|
||||
async def store(self, settings: Settings) -> None:
|
||||
json_str = settings.model_dump_json(context={'expose_secrets': True})
|
||||
await call_sync_from_async(self.file_store.write, self.path, json_str)
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ class SettingsStore(ABC):
|
||||
"""Load session init data"""
|
||||
|
||||
@abstractmethod
|
||||
async def store(self, settings: Settings):
|
||||
async def store(self, settings: Settings) -> None:
|
||||
"""Store session init data"""
|
||||
|
||||
@classmethod
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user