Compare commits

...

5 Commits

Author SHA1 Message Date
Devin AI
e0d3d859d2 Fix Crewai alias implementation to preserve type checking
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-31 12:59:51 +00:00
Devin AI
9803a964c9 Fix import formatting issues in crew.py and test_crewai_alias.py
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-31 12:54:04 +00:00
Devin AI
7079fce4b1 Fix import formatting issues in test file
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-31 12:50:51 +00:00
Devin AI
f57fc521f8 Address PR feedback: improve documentation, add deprecation warning, enhance test coverage
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-31 12:48:55 +00:00
Devin AI
d1fd44f477 Fix #2500: Add Crewai alias for backward compatibility
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-03-31 12:41:06 +00:00
2 changed files with 86 additions and 1 deletions

View File

@@ -1,12 +1,24 @@
import asyncio
import json
import re
import sys
import uuid
import warnings
from concurrent.futures import Future
from copy import copy as shallow_copy
from hashlib import md5
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union, cast
from typing import (
Any,
Callable,
Dict,
List,
Optional,
Set,
Tuple,
TypeAlias,
Union,
cast,
)
from pydantic import (
UUID4,
@@ -1384,3 +1396,19 @@ class Crew(BaseModel):
memory_system.reset()
except Exception as e:
raise RuntimeError(f"Failed to reset {name} memory") from e
class Crewai(Crew):
"""Alias for Crew class to provide backward compatibility.
This class inherits from Crew and provides the same functionality,
but emits a deprecation warning when used.
"""
def __new__(cls, *args, **kwargs):
warnings.warn(
"Crewai is deprecated, use Crew instead.",
DeprecationWarning,
stacklevel=2
)
return super().__new__(cls)

View File

@@ -0,0 +1,57 @@
import unittest
class TestCrewaiAlias(unittest.TestCase):
"""Tests validating the Crewai alias and its backward compatibility.
These tests ensure that the Crewai alias works correctly for both
import scenarios and practical usage, providing backward compatibility
for existing code that uses the 'Crewai' name.
"""
def test_crewai_alias_import(self):
"""Test that Crewai can be imported from crewai.crew."""
try:
from crewai.crew import Crew, Crewai
self.assertEqual(Crewai, Crew)
except ImportError:
self.fail("Failed to import Crewai from crewai.crew")
def test_crewai_instance_creation(self):
"""Ensure Crewai can be instantiated just like Crew."""
from crewai.agent import Agent
from crewai.crew import Crew, Crewai
test_agent = Agent(
role="Test Agent",
goal="Testing",
backstory="Created for testing"
)
crewai_instance = Crewai(agents=[test_agent], tasks=[])
crew_instance = Crew(agents=[test_agent], tasks=[])
self.assertIsInstance(crewai_instance, Crew)
self.assertEqual(type(crewai_instance), type(crew_instance))
def test_crewai_deprecation_warning(self):
"""Test that using Crewai emits a deprecation warning."""
import importlib
import warnings
import crewai.crew
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
importlib.reload(crewai.crew)
self.assertTrue(len(w) > 0, "No deprecation warning was captured")
self.assertTrue(any(issubclass(warning.category, DeprecationWarning) for warning in w),
"No DeprecationWarning was found")
self.assertTrue(any("Crewai is deprecated" in str(warning.message) for warning in w),
"Warning message doesn't contain expected text")
if __name__ == "__main__":
unittest.main()