diff --git a/.github/workflows/type-checker.yml b/.github/workflows/type-checker.yml index e2171c53a..e5af4ba9e 100644 --- a/.github/workflows/type-checker.yml +++ b/.github/workflows/type-checker.yml @@ -12,13 +12,13 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.10', '3.11', '3.12', '3.13'] + python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 # Fetch all history for proper diff + fetch-depth: 0 # Fetch all history for proper diff - name: Install uv uses: astral-sh/setup-uv@v6 @@ -40,10 +40,10 @@ jobs: # Get the list of changed Python files compared to the base branch echo "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/ directories grep -E "^(src/|tests/)" changed_files.txt > filtered_changed_files.txt || true - + # Check if there are any changed files if [ -s filtered_changed_files.txt ]; then echo "Changed Python files in src/ and tests/:" diff --git a/src/crewai/__init__.py b/src/crewai/__init__.py index 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 threading import urllib.request @@ -15,17 +41,10 @@ from crewai.tasks.llm_guardrail import LLMGuardrail from crewai.tasks.task_output import TaskOutput from 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)