Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
fix: suppress Pydantic deprecation warnings in initialization (#3443)
Lorenze Jayf4f32b5f7fff
diff --git a/.github/workflows/type-checker.yml b/.github/workflows/type-checker.ymlindex e2171c53a..e5af4ba9e 100644--- a/.github/workflows/type-checker.yml+++ b/.github/workflows/type-checker.yml@@ -12,13 +12,13 @@ jobs:strategy:fail-fast: falsematrix:- python-version: ['3.10', '3.11', '3.12', '3.13']+ python-version: ["3.10", "3.11", "3.12", "3.13"]steps:- name: Checkout codeuses: actions/checkout@v4with:- fetch-depth: 0 # Fetch all history for proper diff+ fetch-depth: 0 # Fetch all history for proper diff- name: Install uvuses: astral-sh/setup-uv@v6@@ -40,10 +40,10 @@ jobs:# Get the list of changed Python files compared to the base branchecho "Fetching changed files..."git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }}...HEAD -- '*.py' > changed_files.txt-+# Filter for files in src/ and tests/ directoriesgrep -E "^(src/|tests/)" changed_files.txt > filtered_changed_files.txt || true-+# Check if there are any changed filesif [ -s filtered_changed_files.txt ]; thenecho "Changed Python files in src/ and tests/:"diff --git a/src/crewai/__init__.py b/src/crewai/__init__.pyindex 1a0505889..f5334713d 100644--- a/src/crewai/__init__.py+++ b/src/crewai/__init__.py@@ -1,4 +1,30 @@import warnings+from typing import Any+++def _suppress_pydantic_deprecation_warnings() -> None:+ """Suppress Pydantic deprecation warnings using targeted monkey patch."""+ original_warn = warnings.warn++ def filtered_warn(+ message: Any,+ category: type | None = None,+ stacklevel: int = 1,+ source: Any = None,+ ) -> Any:+ if (+ category+ and hasattr(category, "__module__")+ and category.__module__ == "pydantic.warnings"+ ):+ return None+ return original_warn(message, category, stacklevel + 1, source)++ setattr(warnings, "warn", filtered_warn)+++_suppress_pydantic_deprecation_warnings()+import threadingimport urllib.request@@ -15,17 +41,10 @@ from crewai.tasks.llm_guardrail import LLMGuardrailfrom crewai.tasks.task_output import TaskOutputfrom crewai.telemetry.telemetry import Telemetry-warnings.filterwarnings(- "ignore",- message="Pydantic serializer warnings:",- category=UserWarning,- module="pydantic.main",-)-_telemetry_submitted = False-def _track_install():+def _track_install() -> None:"""Track package installation/first-use via Scarf analytics."""global _telemetry_submitted@@ -36,7 +55,7 @@ def _track_install():pixel_url = "https://api.scarf.sh/v2/packages/CrewAI/crewai/docs/00f2dad1-8334-4a39-934e-003b2e1146db"req = urllib.request.Request(pixel_url)- req.add_header('User-Agent', f'CrewAI-Python/{__version__}')+ req.add_header("User-Agent", f"CrewAI-Python/{__version__}")with urllib.request.urlopen(req, timeout=2): # nosec B310_telemetry_submitted = True@@ -45,7 +64,7 @@ def _track_install():pass-def _track_install_async():+def _track_install_async() -> None:"""Track installation in background thread to avoid blocking imports."""if not Telemetry._is_telemetry_disabled():thread = threading.Thread(target=_track_install, daemon=True)