diff --git a/pyproject.toml b/pyproject.toml index 3f10c1a87..700c57743 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,6 +30,7 @@ dependencies = [ "pdfplumber>=0.11.4", "openpyxl>=3.1.5", "blinker>=1.9.0", + "typing-extensions>=4.5.0", ] [project.urls] diff --git a/src/crewai/memory/memory.py b/src/crewai/memory/memory.py index 46af2c04d..7b99f7cae 100644 --- a/src/crewai/memory/memory.py +++ b/src/crewai/memory/memory.py @@ -1,5 +1,10 @@ from typing import Any, Dict, List, Optional +try: + from typing import Self +except ImportError: + from typing_extensions import Self + from crewai.memory.storage.rag_storage import RAGStorage diff --git a/tests/compatibility/test_python310_compatibility.py b/tests/compatibility/test_python310_compatibility.py new file mode 100644 index 000000000..796fa628f --- /dev/null +++ b/tests/compatibility/test_python310_compatibility.py @@ -0,0 +1,14 @@ +def test_self_import_compatibility(): + """ + Test that the Self type is properly imported and used + in a way that supports Python 3.10+. + + This test will pass as long as the module imports successfully. + The actual failure would happen during import if the compatibility + fix is not working. + """ + try: + from crewai.memory.memory import Self + assert True, "Self type imported successfully" + except ImportError: + assert False, "Failed to import Self type from crewai.memory.memory"