add ruff and pyright flake checks

This commit is contained in:
Abel Luck 2026-03-05 16:08:31 +01:00
parent 42cf3f75dc
commit 7c9b42fe56
8 changed files with 125 additions and 19 deletions

View file

@ -21,9 +21,11 @@ class ClientCredentials(BaseModel):
class CredentialStorage(Protocol):
def save_config(self, config: ClientCredentials) -> None:
"""Save config"""
...
def read_config(self) -> ClientCredentials:
"""Load config"""
...
class LocalCredentialStore:
@ -64,7 +66,7 @@ class MatrixClient:
self.store_path.joinpath("credentials.json")
)
self.client: AsyncClient = None
self.client: Optional[AsyncClient] = None
self.client_config = AsyncClientConfig(
max_limit_exceeded=0,
max_timeouts=0,
@ -79,15 +81,19 @@ class MatrixClient:
async def start(self) -> None:
await self.login()
if self.client is None:
raise RuntimeError("Matrix client failed to initialize")
if self.client.should_upload_keys:
await self.client.keys_upload()
client = self.client
if client.should_upload_keys:
await client.keys_upload()
for room in self.join_rooms:
await self.client.join(room)
await client.join(room)
await self.client.joined_rooms()
await self.client.sync_forever(timeout=300000, full_state=True)
await client.joined_rooms()
await client.sync_forever(timeout=300000, full_state=True)
def save_credentials(self, resp: LoginResponse, homeserver: str) -> None:
credentials = ClientCredentials(
@ -150,6 +156,9 @@ class MatrixClient:
message: str,
message_formatted: Optional[str] = None,
) -> None:
if self.client is None:
raise RuntimeError("Matrix client failed to initialize")
content = {
"msgtype": "m.text",
"body": f"{message}",
@ -168,4 +177,5 @@ class MatrixClient:
)
async def shutdown(self) -> None:
await self.client.close()
if self.client is not None:
await self.client.close()