fix(mypy): resolve type issues in MongoDB, batches, and auth providers (#3933)

Fixes mypy type errors in provider utilities:
- MongoDB: Fix AsyncMongoClient parameters, use async iteration for
cursor
- Batches: Handle memoryview|bytes union for file decoding
- Auth: Add missing imports, validate JWKS URI, conditionally pass
parameters

Fixes 11 type errors. No functional changes.
This commit is contained in:
Ashwin Bharambe 2025-10-28 10:23:39 -07:00 committed by GitHub
parent 4a2ea278c5
commit 6ce59b5df8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 29 deletions

View file

@ -358,7 +358,11 @@ class ReferenceBatchesImpl(Batches):
# TODO(SECURITY): do something about large files
file_content_response = await self.files_api.openai_retrieve_file_content(batch.input_file_id)
file_content = file_content_response.body.decode("utf-8")
# Handle both bytes and memoryview types
body = file_content_response.body
if isinstance(body, memoryview):
body = bytes(body)
file_content = body.decode("utf-8")
for line_num, line in enumerate(file_content.strip().split("\n"), 1):
if line.strip(): # skip empty lines
try:

View file

@ -30,14 +30,13 @@ class MongoDBKVStoreImpl(KVStore):
async def initialize(self) -> None:
try:
conn_creds = {
"host": self.config.host,
"port": self.config.port,
"username": self.config.user,
"password": self.config.password,
}
conn_creds = {k: v for k, v in conn_creds.items() if v is not None}
self.conn = AsyncMongoClient(**conn_creds)
# Pass parameters explicitly to satisfy mypy - AsyncMongoClient doesn't accept **dict
self.conn = AsyncMongoClient(
host=self.config.host if self.config.host is not None else None,
port=self.config.port if self.config.port is not None else None,
username=self.config.user if self.config.user is not None else None,
password=self.config.password if self.config.password is not None else None,
)
except Exception as e:
log.exception("Could not connect to MongoDB database server")
raise RuntimeError("Could not connect to MongoDB database server") from e
@ -79,4 +78,8 @@ class MongoDBKVStoreImpl(KVStore):
end_key = self._namespaced_key(end_key)
query = {"key": {"$gte": start_key, "$lt": end_key}}
cursor = self.collection.find(query, {"key": 1, "_id": 0}).sort("key", 1)
return [doc["key"] for doc in cursor]
# AsyncCursor requires async iteration
result = []
async for doc in cursor:
result.append(doc["key"])
return result