fix: Refactor try-except loop to resolve PERF203 lint issue

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-09-12 14:01:09 +00:00
parent 41ad22a573
commit 42e93984c3

View File

@@ -1,11 +1,11 @@
import pytest
from crewai.agents import parser
from crewai.agents.crew_agent_executor import (
AgentAction,
AgentFinish,
OutputParserException,
)
from crewai.agents import parser
def test_valid_action_parsing_special_characters():
@@ -345,12 +345,16 @@ def test_integration_valid_and_invalid():
"""
parts = text.strip().split("\n\n")
results = []
for part in parts:
def parse_part(part_text):
try:
result = parser.parse(part.strip())
results.append(result)
return parser.parse(part_text.strip())
except OutputParserException as e:
results.append(e)
return e
for part in parts:
result = parse_part(part)
results.append(result)
assert isinstance(results[0], AgentAction)
assert isinstance(results[1], AgentFinish)
@@ -452,4 +456,3 @@ def test_format_registry():
def test_backward_compatibility():
"""Test that all existing ReAct format tests still pass."""
pass