chore(lint): Apply comprehensive linting and formatting fixes (#10287)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Xingyao Wang
2025-08-13 15:13:19 -04:00
committed by GitHub
parent e39bf80239
commit c2f46200c0
164 changed files with 526 additions and 1023 deletions

View File

@@ -7,9 +7,7 @@ from openhands.storage.data_models.conversation_status import ConversationStatus
@dataclass
class AgentLoopInfo:
"""
Information about an agent loop - the URL on which to locate it and the event store
"""
"""Information about an agent loop - the URL on which to locate it and the event store"""
conversation_id: str
url: str | None

View File

@@ -9,8 +9,7 @@ from openhands.storage.data_models.conversation_status import ConversationStatus
@dataclass
class ConversationInfo:
"""
Information about a conversation. This combines conversation metadata with
"""Information about a conversation. This combines conversation metadata with
information on whether a conversation is currently running
"""

View File

@@ -10,8 +10,7 @@ _SESSION_API_KEY_HEADER = APIKeyHeader(name='X-Session-API-Key', auto_error=Fals
def check_session_api_key(
session_api_key: str | None = Depends(_SESSION_API_KEY_HEADER),
):
"""
Check the session API key and throw an exception if incorrect. Having this as a dependency
"""Check the session API key and throw an exception if incorrect. Having this as a dependency
means it appears in OpenAPI Docs
"""
if session_api_key != _SESSION_API_KEY:

View File

@@ -4,9 +4,7 @@ from pydantic import (
class POSTUploadFilesModel(BaseModel):
"""
Upload files response model
"""
"""Upload files response model"""
file_urls: list[str]
skipped_files: list[str]

View File

@@ -14,8 +14,7 @@ from starlette.types import ASGIApp
class LocalhostCORSMiddleware(CORSMiddleware):
"""
Custom CORS middleware that allows any request from localhost/127.0.0.1 domains,
"""Custom CORS middleware that allows any request from localhost/127.0.0.1 domains,
while using standard CORS rules for other origins.
"""
@@ -50,9 +49,7 @@ class LocalhostCORSMiddleware(CORSMiddleware):
class CacheControlMiddleware(BaseHTTPMiddleware):
"""
Middleware to disable caching for all routes by adding appropriate headers
"""
"""Middleware to disable caching for all routes by adding appropriate headers"""
async def dispatch(
self, request: Request, call_next: RequestResponseEndpoint

View File

@@ -17,22 +17,18 @@ class MonitoringListener:
"""
def on_session_event(self, event: Event) -> None:
"""
Track metrics about events being added to a Session's EventStream.
"""
"""Track metrics about events being added to a Session's EventStream."""
pass
def on_agent_session_start(self, success: bool, duration: float) -> None:
"""
Track an agent session start.
"""Track an agent session start.
Success is true if startup completed without error.
Duration is start time in seconds observed by AgentSession.
"""
pass
def on_create_conversation(self) -> None:
"""
Track the beginning of conversation creation.
"""Track the beginning of conversation creation.
Does not currently capture whether it succeed.
"""
pass

View File

@@ -114,6 +114,7 @@ async def search_events(
user_id: str | None = Depends(get_user_id),
):
"""Search through the event stream with filtering and pagination.
Args:
conversation_id: The conversation ID
start_id: Starting ID in the event stream. Defaults to 0
@@ -123,6 +124,7 @@ async def search_events(
limit: Maximum number of events to return. Must be between 1 and 100. Defaults to 20
metadata: Conversation metadata (injected by dependency)
user_id: User ID (injected by dependency)
Returns:
dict: Dictionary containing:
- events: List of matching events

View File

@@ -626,7 +626,6 @@ async def update_conversation(
Raises:
HTTPException: If conversation is not found or user lacks permission
"""
logger.info(
f'Updating conversation {conversation_id} with title: {data.title}',
extra={'session_id': conversation_id, 'user_id': user_id},

View File

@@ -32,10 +32,7 @@ CONVO_URL = HOST + '/conversations/{}'
async def get_convo_link(service: GitService, conversation_id: str, body: str) -> str:
"""
Appends a followup link, in the PR body, to the OpenHands conversation that opened the PR
"""
"""Appends a followup link, in the PR body, to the OpenHands conversation that opened the PR"""
if server_config.app_mode != AppMode.SAAS:
return body
@@ -94,7 +91,6 @@ async def create_pr(
] = None,
) -> str:
"""Open a PR in GitHub"""
logger.info('Calling OpenHands MCP create_pr')
request = get_http_request()
@@ -165,7 +161,6 @@ async def create_mr(
] = None,
) -> str:
"""Open a MR in GitLab"""
logger.info('Calling OpenHands MCP create_mr')
request = get_http_request()
@@ -233,7 +228,6 @@ async def create_bitbucket_pr(
description: Annotated[str | None, Field(description='PR description')],
) -> str:
"""Open a PR in Bitbucket"""
logger.info('Calling OpenHands MCP create_bitbucket_pr')
request = get_http_request()

View File

@@ -33,12 +33,10 @@ app = APIRouter(prefix='/api', dependencies=get_dependencies())
async def invalidate_legacy_secrets_store(
settings: Settings, settings_store: SettingsStore, secrets_store: SecretsStore
) -> UserSecrets | None:
"""
We are moving `secrets_store` (a field from `Settings` object) to its own dedicated store
"""We are moving `secrets_store` (a field from `Settings` object) to its own dedicated store
This function moves the values from Settings to UserSecrets, and deletes the values in Settings
While this function in called multiple times, the migration only ever happens once
"""
if len(settings.secrets_store.provider_tokens.items()) > 0:
user_secrets = UserSecrets(
provider_tokens=settings.secrets_store.provider_tokens

View File

@@ -97,9 +97,7 @@ async def load_settings(
},
)
async def reset_settings() -> JSONResponse:
"""
Resets user settings. (Deprecated)
"""
"""Resets user settings. (Deprecated)"""
logger.warning('Deprecated endpoint /api/reset-settings called by user')
return JSONResponse(
status_code=status.HTTP_410_GONE,

View File

@@ -164,7 +164,6 @@ async def setup_init_convo_settings(
) -> ConversationInitData:
"""Set up conversation initialization data with provider tokens.
Args:
user_id: The user ID
conversation_id: The conversation ID

View File

@@ -72,7 +72,6 @@ class AgentSession:
- sid: The session ID
- file_store: Instance of the FileStore
"""
self.sid = sid
self.event_stream = EventStream(sid, file_store, user_id)
self.file_store = file_store
@@ -253,8 +252,7 @@ class AgentSession:
agent_to_llm_config: dict[str, LLMConfig] | None,
agent_configs: dict[str, AgentConfig] | None,
) -> MessageAction:
"""
Replays a trajectory from a JSON file. Note that once the replay session
"""Replays a trajectory from a JSON file. Note that once the replay session
finishes, the controller will continue to run with further user instructions,
so we still need to pass llm configs, budget, etc., even though the replay
itself does not call LLM or cost money.
@@ -279,7 +277,6 @@ class AgentSession:
Parameters:
- security_analyzer: The name of the security analyzer to use
"""
if security_analyzer:
self.logger.debug(f'Using security analyzer: {security_analyzer}')
self.security_analyzer = options.SecurityAnalyzers.get(
@@ -325,7 +322,6 @@ class AgentSession:
Return True on successfully connected, False if could not connect.
Raises if already created, possibly in other situations.
"""
if self.runtime is not None:
raise RuntimeError('Runtime already created')
@@ -422,7 +418,6 @@ class AgentSession:
Returns:
Agent Controller and a bool indicating if state was restored from a previous conversation
"""
if self.controller is not None:
raise RuntimeError('Controller already created')
if self.runtime is None:

View File

@@ -6,9 +6,7 @@ from openhands.storage.data_models.settings import Settings
class ConversationInitData(Settings):
"""
Session initialization data for the web environment - a deep copy of the global config is made and then overridden with this data.
"""
"""Session initialization data for the web environment - a deep copy of the global config is made and then overridden with this data."""
git_provider_tokens: PROVIDER_TOKEN_TYPE | None = Field(default=None, frozen=True)
custom_secrets: CUSTOM_SECRETS_TYPE | None = Field(default=None, frozen=True)

View File

@@ -13,26 +13,20 @@ from openhands.storage.data_models.settings import Settings
class POSTProviderModel(BaseModel):
"""
Settings for POST requests
"""
"""Settings for POST requests"""
mcp_config: MCPConfig | None = None
provider_tokens: dict[ProviderType, ProviderToken] = {}
class POSTCustomSecrets(BaseModel):
"""
Adding new custom secret
"""
"""Adding new custom secret"""
custom_secrets: dict[str, CustomSecret] = {}
class GETSettingsModel(Settings):
"""
Settings with additional token data for the frontend
"""
"""Settings with additional token data for the frontend"""
provider_tokens_set: dict[ProviderType, str | None] | None = (
None # provider + base_domain key-value pair
@@ -44,25 +38,19 @@ class GETSettingsModel(Settings):
class CustomSecretWithoutValueModel(BaseModel):
"""
Custom secret model without value
"""
"""Custom secret model without value"""
name: str
description: str | None = None
class CustomSecretModel(CustomSecretWithoutValueModel):
"""
Custom secret model with value
"""
"""Custom secret model with value"""
value: SecretStr
class GETCustomSecrets(BaseModel):
"""
Custom secrets names
"""
"""Custom secrets names"""
custom_secrets: list[CustomSecretWithoutValueModel] | None = None