Support Python 3.10+ (on CI) and remove redundant Self imports (#2553)

* ci(workflows): add Python version matrix (3.10-3.12) for tests

* refactor: remove explicit Self import from typing

Python 3.10+ natively supports Self type annotation without explicit imports

* chore: rename external_memory file test

---------

Co-authored-by: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com>
This commit is contained in:
Lucas Gomide
2025-04-10 15:37:24 -03:00
committed by GitHub
parent 37979a0ca1
commit d2caf11191
4 changed files with 9 additions and 7 deletions

View File

@@ -12,6 +12,9 @@ jobs:
tests: tests:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 15 timeout-minutes: 15
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12']
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -21,9 +24,8 @@ jobs:
with: with:
enable-cache: true enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
- name: Set up Python run: uv python install ${{ matrix.python-version }}
run: uv python install 3.12.8
- name: Install the project - name: Install the project
run: uv sync --dev --all-extras run: uv sync --dev --all-extras

View File

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

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional, Self from typing import Any, Dict, List, Optional
from pydantic import BaseModel from pydantic import BaseModel
@@ -38,6 +38,6 @@ class Memory(BaseModel):
query=query, limit=limit, score_threshold=score_threshold query=query, limit=limit, score_threshold=score_threshold
) )
def set_crew(self, crew: Any) -> Self: def set_crew(self, crew: Any) -> "Memory":
self.crew = crew self.crew = crew
return self return self