π OpenHands: AI-Driven Development
Refactor: Shorter syntax. (#4753)
tofarrdf9e9fca5a7f
diff --git a/openhands/__init__.py b/openhands/__init__.pyindex dfd64a7440..531f084443 100644--- a/openhands/__init__.py+++ b/openhands/__init__.py@@ -6,22 +6,14 @@ __package_name__ = 'openhands_ai'def get_version():try:from importlib.metadata import PackageNotFoundError, version-- try:- return version(__package_name__)- except PackageNotFoundError:- pass- except ImportError:+ return version(__package_name__)+ except (ImportError, PackageNotFoundError):passtry:from pkg_resources import DistributionNotFound, get_distribution-- try:- return get_distribution(__package_name__).version- except DistributionNotFound:- pass- except ImportError:+ return get_distribution(__package_name__).version+ except (ImportError, DistributionNotFound):pass# Try getting the version from pyproject.tomldiff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.pyindex 8899e5e15b..b897eae691 100644--- a/openhands/controller/agent_controller.py+++ b/openhands/controller/agent_controller.py@@ -312,7 +312,7 @@ class AgentController:if new_state == self.state.agent_state:return- if new_state == AgentState.STOPPED or new_state == AgentState.ERROR:+ if new_state in (AgentState.STOPPED, AgentState.ERROR):self.reset_task()elif (new_state == AgentState.RUNNING@@ -338,8 +338,7 @@ class AgentController:if self.state.metrics.accumulated_cost >= self.max_budget_per_task:self.max_budget_per_task += self._initial_max_budget_per_taskelif self._pending_action is not None and (- new_state == AgentState.USER_CONFIRMED- or new_state == AgentState.USER_REJECTED+ new_state in (AgentState.USER_CONFIRMED, AgentState.USER_REJECTED)):if hasattr(self._pending_action, 'thought'):self._pending_action.thought = '' # type: ignore[union-attr]diff --git a/openhands/server/session/session.py b/openhands/server/session/session.pyindex 59dd8a0295..859d6a41c9 100644--- a/openhands/server/session/session.py+++ b/openhands/server/session/session.py@@ -182,10 +182,7 @@ class Session:await asyncio.sleep(0.001) # This flushes the data to the clientself.last_active_ts = int(time.time())return True- except RuntimeError:- self.is_alive = False- return False- except WebSocketDisconnect:+ except (RuntimeError, WebSocketDisconnect):self.is_alive = Falsereturn False