From d3951bd850d64bb074e575f26b497660d8277f4b Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Wed, 29 Oct 2025 10:14:04 +0100 Subject: [PATCH] fix: add ruff check to CI and fix all lint errors - Add 'Lint with ruff' step to CI workflow (was only running format check) - Fix F401: Add explicit re-exports for public API types in __init__.py - Fix F811: Rename duplicate test_openai_reasoning_tokens to test_openai_reasoning_tokens_o4_mini - Fix E731: Convert lambda to def function in test_middleware.py - Fix unused imports in client.py and test files (auto-fixed) Without ruff check in CI, lint errors were accumulating on master undetected. --- .github/workflows/ci.yml | 4 ++++ posthog/__init__.py | 11 +++++++++-- posthog/client.py | 3 +-- posthog/test/ai/anthropic/test_anthropic.py | 1 - posthog/test/ai/langchain/test_callbacks.py | 2 +- posthog/test/integrations/test_middleware.py | 4 +++- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a181988..7e531408 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,10 @@ jobs: run: | ruff format --check . + - name: Lint with ruff + run: | + ruff check . + - name: Check types with mypy run: | mypy --no-site-packages --config-file mypy.ini . | mypy-baseline filter diff --git a/posthog/__init__.py b/posthog/__init__.py index d4d62682..8db0ca06 100644 --- a/posthog/__init__.py +++ b/posthog/__init__.py @@ -11,8 +11,15 @@ set_context_session as inner_set_context_session, identify_context as inner_identify_context, ) -from posthog.feature_flags import InconclusiveMatchError, RequiresServerEvaluation -from posthog.types import FeatureFlag, FlagsAndPayloads, FeatureFlagResult +from posthog.feature_flags import ( + InconclusiveMatchError as InconclusiveMatchError, + RequiresServerEvaluation as RequiresServerEvaluation, +) +from posthog.types import ( + FeatureFlag, + FlagsAndPayloads, + FeatureFlagResult as FeatureFlagResult, +) from posthog.version import VERSION __version__ = VERSION diff --git a/posthog/client.py b/posthog/client.py index 620064f6..6658f88c 100644 --- a/posthog/client.py +++ b/posthog/client.py @@ -3,7 +3,7 @@ import os import sys from datetime import datetime, timedelta -from typing import Any, Callable, Dict, Optional, Union +from typing import Any, Dict, Optional, Union from typing_extensions import Unpack from uuid import uuid4 @@ -60,7 +60,6 @@ SizeLimitedDict, clean, guess_timezone, - remove_trailing_slash, system_context, ) from posthog.version import VERSION diff --git a/posthog/test/ai/anthropic/test_anthropic.py b/posthog/test/ai/anthropic/test_anthropic.py index 5f65a99e..640d7770 100644 --- a/posthog/test/ai/anthropic/test_anthropic.py +++ b/posthog/test/ai/anthropic/test_anthropic.py @@ -1,4 +1,3 @@ -import os from unittest.mock import patch import pytest diff --git a/posthog/test/ai/langchain/test_callbacks.py b/posthog/test/ai/langchain/test_callbacks.py index b6e74e6b..b181beec 100644 --- a/posthog/test/ai/langchain/test_callbacks.py +++ b/posthog/test/ai/langchain/test_callbacks.py @@ -1716,7 +1716,7 @@ def test_combined_reasoning_and_cache_tokens(mock_client): @pytest.mark.skipif(not OPENAI_API_KEY, reason="OPENAI_API_KEY is not set") -def test_openai_reasoning_tokens(mock_client): +def test_openai_reasoning_tokens_o4_mini(mock_client): model = ChatOpenAI( api_key=OPENAI_API_KEY, model="o4-mini", max_completion_tokens=10 ) diff --git a/posthog/test/integrations/test_middleware.py b/posthog/test/integrations/test_middleware.py index 777e13f9..a26c9b30 100644 --- a/posthog/test/integrations/test_middleware.py +++ b/posthog/test/integrations/test_middleware.py @@ -235,7 +235,9 @@ def test_sync_middleware_with_filter(self): get_response = Mock(return_value=mock_response) # Create middleware with request filter that filters all requests - request_filter = lambda req: False + def request_filter(req): + return False + middleware = PosthogContextMiddleware.__new__(PosthogContextMiddleware) middleware.get_response = get_response middleware._is_coroutine = False