Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Add more extensive typing to openhands/integrations directory (#7730)

Graham Neubigc8904e4672aa
diff --git a/openhands/integrations/github/github_service.py b/openhands/integrations/github/github_service.py
index 82442318db..9e66873ad3 100644
--- a/openhands/integrations/github/github_service.py
+++ b/openhands/integrations/github/github_service.py
@@ -100,7 +100,6 @@ class GitHubService(GitService):
email=response.get('email'),
)
-
async def _fetch_paginated_repos(
self, url: str, params: dict, max_repos: int, extract_key: str | None = None
) -> list[dict]:
@@ -204,7 +203,7 @@ class GitHubService(GitService):
}
response, _ = await self._fetch_data(url, params)
- repos = response.get('items', [])
+ repo_items = response.get('items', [])
repos = [
Repository(
@@ -213,7 +212,7 @@ class GitHubService(GitService):
stargazers_count=repo.get('stargazers_count'),
git_provider=ProviderType.GITHUB,
)
- for repo in repos
+ for repo in repo_items
]
return repos
@@ -238,7 +237,7 @@ class GitHubService(GitService):
f"GraphQL query error: {json.dumps(result['errors'])}"
)
- return result
+ return dict(result)
except httpx.HTTPStatusError as e:
if e.response.status_code == 401:
diff --git a/openhands/integrations/gitlab/gitlab_service.py b/openhands/integrations/gitlab/gitlab_service.py
index 1b40987b88..6c711f600a 100644
--- a/openhands/integrations/gitlab/gitlab_service.py
+++ b/openhands/integrations/gitlab/gitlab_service.py
@@ -1,6 +1,5 @@
import os
from typing import Any
-from urllib.parse import quote_plus
import httpx
from pydantic import SecretStr
diff --git a/openhands/integrations/provider.py b/openhands/integrations/provider.py
index 03939d34d8..fed04f31cc 100644
--- a/openhands/integrations/provider.py
+++ b/openhands/integrations/provider.py
@@ -74,7 +74,7 @@ class SecretStore(BaseModel):
@field_serializer('provider_tokens')
def provider_tokens_serializer(
self, provider_tokens: PROVIDER_TOKEN_TYPE, info: SerializationInfo
- ):
+ ) -> dict[str, dict[str, str | Any]]:
tokens = {}
expose_secrets = info.context and info.context.get('expose_secrets', False)
@@ -100,12 +100,12 @@ class SecretStore(BaseModel):
@classmethod
def convert_dict_to_mappingproxy(
cls, data: dict[str, dict[str, dict[str, str]]] | PROVIDER_TOKEN_TYPE
- ) -> dict[str, MappingProxyType]:
+ ) -> dict[str, MappingProxyType[Any, Any]]:
"""Custom deserializer to convert dictionary into MappingProxyType"""
if not isinstance(data, dict):
raise ValueError('SecretStore must be initialized with a dictionary')
- new_data = {}
+ new_data: dict[str, MappingProxyType[Any, Any]] = {}
if 'provider_tokens' in data:
tokens = data['provider_tokens']
@@ -210,7 +210,7 @@ class ProviderHandler:
per_page: int,
sort: str,
order: str,
- ):
+ ) -> list[Repository]:
all_repos: list[Repository] = []
for provider in self.provider_tokens:
try:
@@ -228,7 +228,7 @@ class ProviderHandler:
self,
event_stream: EventStream,
env_vars: dict[ProviderType, SecretStr] | None = None,
- ):
+ ) -> None:
"""
This ensures that the latest provider tokens are masked from the event stream
It is called when the provider tokens are first initialized in the runtime or when tokens are re-exported with the latest working ones