From c4e1f75235a288afad4c7d48c60a49e737a1fe9f Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 10 Apr 2025 16:32:13 +0000 Subject: [PATCH] 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 --- pyproject.toml | 1 + src/crewai/memory/memory.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d85c43c93..de25bcbb6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/crewai/memory/memory.py b/src/crewai/memory/memory.py index ba8c10a29..ca3cb2648 100644 --- a/src/crewai/memory/memory.py +++ b/src/crewai/memory/memory.py @@ -1,4 +1,10 @@ -from typing import Any, Dict, List, Optional, Self +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