Skip to content

Commit 3d5e665

Browse files
refactor: simplify redundant hasattr checks and fix test formatting
- Remove redundant hasattr checks in agent.py as getattr handles missing attributes - Fix unnecessary f-string prefixes in test file - Remove unused variable assignment in test Co-authored-by: Mervin Praison <[email protected]>
1 parent b95579d commit 3d5e665

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/praisonai-agents/praisonaiagents/agent/agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,9 +1945,9 @@ async def aexecute(self, task, context=None):
19451945
else:
19461946
prompt = str(task)
19471947
# Extract task info if available
1948-
task_name = getattr(task, 'name', None) if hasattr(task, 'name') else None
1949-
task_description = getattr(task, 'description', None) if hasattr(task, 'description') else None
1950-
task_id = getattr(task, 'id', None) if hasattr(task, 'id') else None
1948+
task_name = getattr(task, 'name', None)
1949+
task_description = getattr(task, 'description', None)
1950+
task_id = getattr(task, 'id', None)
19511951
return await self.achat(prompt, task_name=task_name, task_description=task_description, task_id=task_id)
19521952

19531953
async def execute_tool_async(self, function_name: str, arguments: Dict[str, Any]) -> Any:

test_task_name_fix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_achat_signature():
3939
print(f" ❌ Missing parameters: {missing_params}")
4040
return False
4141
else:
42-
print(f" ✅ All required parameters present")
42+
print(" ✅ All required parameters present")
4343
return True
4444

4545
except Exception as e:
@@ -76,7 +76,7 @@ def test_task_structure():
7676
has_id = hasattr(task, 'id')
7777

7878
if has_name and has_description and has_id:
79-
print(f" ✅ Task has all required attributes")
79+
print(" ✅ Task has all required attributes")
8080
return True
8181
else:
8282
print(f" ❌ Task missing attributes - name: {has_name}, description: {has_description}, id: {has_id}")
@@ -104,13 +104,13 @@ async def test_achat_call():
104104
# This should not raise a NameError for task_name anymore
105105
try:
106106
# We expect this to fail due to mock LLM, but NOT due to NameError: task_name not defined
107-
response = await agent.achat(
107+
await agent.achat(
108108
"Test prompt",
109109
task_name="test_task",
110110
task_description="Test description",
111111
task_id="test_id"
112112
)
113-
print(f" ✅ achat call succeeded (unexpected but good!)")
113+
print(" ✅ achat call succeeded (unexpected but good!)")
114114
return True
115115
except NameError as e:
116116
if "task_name" in str(e):

0 commit comments

Comments
 (0)