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

@@ -79,8 +79,7 @@ def split_bash_commands(commands: str) -> list[str]:
def escape_bash_special_chars(command: str) -> str:
r"""
Escapes characters that have different interpretations in bash vs python.
r"""Escapes characters that have different interpretations in bash vs python.
Specifically handles escape sequences like \;, \|, \&, etc.
"""
if command.strip() == '':
@@ -446,6 +445,7 @@ class BashSession:
ps1_matches: List of regex matches for PS1 prompts
get_content_before_last_match: when there's only one PS1 match, whether to get
the content before the last PS1 prompt (True) or after the last PS1 prompt (False)
Returns:
Combined string of all outputs between matches
"""

View File

@@ -1,6 +1,4 @@
"""
Utility module for generating file viewer HTML content.
"""
"""Utility module for generating file viewer HTML content."""
import base64
import mimetypes
@@ -8,8 +6,7 @@ import os
def generate_file_viewer_html(file_path: str) -> str:
"""
Generate HTML content for viewing different file types.
"""Generate HTML content for viewing different file types.
Args:
file_path: The absolute path to the file

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""
Get git changes in the current working directory relative to the remote origin if possible.
"""Get git changes in the current working directory relative to the remote origin if possible.
NOTE: Since this is run as a script, there should be no imports from project files!
"""

View File

@@ -1,6 +1,5 @@
#!/usr/bin/env python3
"""
Get git diff in a single git file for the closest git repo in the file system
"""Get git diff in a single git file for the closest git repo in the file system
NOTE: Since this is run as a script, there should be no imports from project files!
"""

View File

@@ -14,8 +14,7 @@ GIT_DIFF_CMD = (
@dataclass
class CommandResult:
"""
Represents the result of a shell command execution.
"""Represents the result of a shell command execution.
Attributes:
content (str): The output content of the command.
@@ -27,9 +26,7 @@ class CommandResult:
class GitHandler:
"""
A handler for executing Git-related operations via shell commands.
"""
"""A handler for executing Git-related operations via shell commands."""
def __init__(
self,
@@ -43,8 +40,7 @@ class GitHandler:
self.git_diff_cmd = GIT_DIFF_CMD
def set_cwd(self, cwd: str) -> None:
"""
Sets the current working directory for Git operations.
"""Sets the current working directory for Git operations.
Args:
cwd (str): The directory path.
@@ -60,8 +56,7 @@ class GitHandler:
return script_file
def get_git_changes(self) -> list[dict[str, str]] | None:
"""
Retrieves the list of changed files in Git repositories.
"""Retrieves the list of changed files in Git repositories.
Examines each direct subdirectory of the workspace directory looking for git repositories
and returns the changes for each of these directories.
Optimized to use a single git command per repository for maximum performance.
@@ -100,8 +95,7 @@ class GitHandler:
return self.get_git_changes()
def get_git_diff(self, file_path: str) -> dict[str, str]:
"""
Retrieves the original and modified content of a file in the repository.
"""Retrieves the original and modified content of a file in the repository.
Args:
file_path (str): Path to the file.

View File

@@ -1,5 +1,4 @@
"""
This module provides a Windows-specific implementation for running commands
"""This module provides a Windows-specific implementation for running commands
in a PowerShell session using the pythonnet library to interact with the .NET
PowerShell SDK directly. This aims to provide a more robust and integrated
way to manage PowerShell processes compared to using temporary script files.
@@ -95,8 +94,7 @@ except Exception as e:
class WindowsPowershellSession:
"""
Manages a persistent PowerShell session using the .NET SDK via pythonnet.
"""Manages a persistent PowerShell session using the .NET SDK via pythonnet.
Allows executing commands within a single runspace, preserving state
(variables, current directory) between calls.
@@ -110,8 +108,7 @@ class WindowsPowershellSession:
no_change_timeout_seconds: int = 30,
max_memory_mb: int | None = None,
):
"""
Initializes the PowerShell session.
"""Initializes the PowerShell session.
Args:
work_dir: The starting working directory for the session.
@@ -388,9 +385,7 @@ class WindowsPowershellSession:
def _check_active_job(
self, timeout_seconds: int
) -> CmdOutputObservation | ErrorObservation:
"""
Checks the active job for new output and status, waiting up to timeout_seconds.
"""
"""Checks the active job for new output and status, waiting up to timeout_seconds."""
with self._job_lock:
if not self.active_job:
return ErrorObservation(
@@ -649,8 +644,7 @@ class WindowsPowershellSession:
return self._cwd
def execute(self, action: CmdRunAction) -> CmdOutputObservation | ErrorObservation:
"""
Executes a command, potentially as a PowerShell background job for long-running tasks.
"""Executes a command, potentially as a PowerShell background job for long-running tasks.
Aligned with bash.py behavior regarding command execution and messages.
Args:

View File

@@ -1,11 +1,8 @@
"""
Custom exceptions for Windows-specific runtime issues.
"""
"""Custom exceptions for Windows-specific runtime issues."""
class DotNetMissingError(Exception):
"""
Exception raised when .NET SDK or CoreCLR is missing or cannot be loaded.
"""Exception raised when .NET SDK or CoreCLR is missing or cannot be loaded.
This is used to provide a cleaner error message to users without a full stack trace.
"""