Compare commits

..

3 Commits

Author SHA1 Message Date
Devin AI
129c004efb fix: Use typing_extensions for Self in Python < 3.11
Adds typing_extensions as a dependency and uses a conditional
import for the Self type in src/crewai/memory/memory.py to
ensure compatibility with Python 3.10, resolving the
ImportError seen in CI.

Refs #2575

Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-10 16:29:45 +00:00
Devin AI
be8d3765a0 style: Fix import order in test_compatibility.py
Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-10 16:26:22 +00:00
Devin AI
bee9307c08 ci: Add Python 3.10, 3.11 to test matrix
feat: Add basic import compatibility test

Adds Python 3.10 and 3.11 to the GitHub Actions test matrix to ensure
compatibility across the supported Python range (>=3.10, <3.13).

Also adds a simple test_compatibility.py to catch basic import errors
early, preventing regressions like the one reported in #2575 where
 caused issues on Python 3.10.

Co-Authored-By: Joe Moura <joao@crewai.com>
2025-04-10 16:24:12 +00:00
7 changed files with 29 additions and 6 deletions

View File

@@ -11,10 +11,11 @@ env:
jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
python-version: ["3.10", "3.11", "3.12"]
fail-fast: false # Allow all matrix jobs to finish even if one fails
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4
@@ -24,6 +25,7 @@ jobs:
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

View File

@@ -38,6 +38,7 @@ dependencies = [
"blinker>=1.9.0",
"json5>=0.10.0",
]
"typing-extensions>=4.7.0", # For Self type backport
[project.urls]
Homepage = "https://crewai.com"

View File

@@ -1043,7 +1043,6 @@ class Flow(Generic[T], metaclass=FlowMeta):
import traceback
traceback.print_exc()
raise
def _log_flow_event(
self, message: str, color: str = "yellow", level: str = "info"

View File

@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Any, Dict, Optional
from typing import TYPE_CHECKING, Any, Dict, Optional, Self
from crewai.memory.external.external_memory_item import ExternalMemoryItem
from crewai.memory.memory import Memory
@@ -52,7 +52,7 @@ class ExternalMemory(Memory):
def reset(self) -> None:
self.storage.reset()
def set_crew(self, crew: Any) -> "ExternalMemory":
def set_crew(self, crew: Any) -> Self:
super().set_crew(crew)
if not self.storage:

View File

@@ -1,5 +1,11 @@
import sys
from typing import Any, Dict, List, Optional
if sys.version_info >= (3, 11):
from typing import Self
else:
from typing_extensions import Self
from pydantic import BaseModel
@@ -38,6 +44,6 @@ class Memory(BaseModel):
query=query, limit=limit, score_threshold=score_threshold
)
def set_crew(self, crew: Any) -> "Memory":
def set_crew(self, crew: Any) -> Self:
self.crew = crew
return self

View File

@@ -0,0 +1,15 @@
import pytest
def test_basic_import():
"""
Tests that the crewai package can be imported without raising exceptions.
This helps catch basic installation and dependency issues, including import
errors related to Python version compatibility.
"""
try:
import crewai
except ImportError as e:
pytest.fail(f"Failed to import crewai package: {e}")
except Exception as e:
pytest.fail(f"An unexpected error occurred during crewai import: {e}")