Skip to content

Commit 5da75a8

Browse files
committed
refactor(agent-server): extract _normalize_hook_config helper to reduce duplication
Address PR feedback about DRY violation - the "check if not None and is_empty(), then set to None" pattern was repeated twice.
1 parent 553890a commit 5da75a8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

openhands-agent-server/openhands/agent_server/event_service.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
logger = get_logger(__name__)
3737

3838

39+
def _normalize_hook_config(config: HookConfig | None) -> HookConfig | None:
40+
"""Return None if config is None or empty, otherwise return config."""
41+
return None if config is None or config.is_empty() else config
42+
43+
3944
@dataclass
4045
class EventService:
4146
"""
@@ -445,9 +450,7 @@ async def start(self):
445450
self._pub_sub, loop=asyncio.get_running_loop()
446451
)
447452

448-
request_hook_config = self.stored.hook_config
449-
if request_hook_config is not None and request_hook_config.is_empty():
450-
request_hook_config = None
453+
request_hook_config = _normalize_hook_config(self.stored.hook_config)
451454

452455
try:
453456
file_hook_config = HookConfig.load(working_dir=workspace.working_dir)
@@ -458,8 +461,7 @@ async def start(self):
458461
exc,
459462
)
460463
file_hook_config = None
461-
if file_hook_config is not None and file_hook_config.is_empty():
462-
file_hook_config = None
464+
file_hook_config = _normalize_hook_config(file_hook_config)
463465

464466
hook_configs: list[HookConfig] = []
465467
if request_hook_config is not None:

0 commit comments

Comments
 (0)