From fb571243b4795fe6f17f126ba3b15ce1bbea7793 Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Wed, 29 Oct 2025 10:14:04 +0100 Subject: [PATCH 1/2] 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/test/ai/langchain/test_callbacks.py | 2 +- posthog/test/integrations/test_middleware.py | 4 +++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec122331..575b5dc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,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 170a3180..98286dd7 100644 --- a/posthog/__init__.py +++ b/posthog/__init__.py @@ -18,8 +18,15 @@ DEFAULT_CODE_VARIABLES_IGNORE_PATTERNS, DEFAULT_CODE_VARIABLES_MASK_PATTERNS, ) -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/test/ai/langchain/test_callbacks.py b/posthog/test/ai/langchain/test_callbacks.py index a1d96c1b..51d8339b 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 403c1b67..18f5309f 100644 --- a/posthog/test/integrations/test_middleware.py +++ b/posthog/test/integrations/test_middleware.py @@ -315,7 +315,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 From 09c28e7a8077dd418f311f4efb77c3f111e496e4 Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Mon, 10 Nov 2025 10:37:39 +0100 Subject: [PATCH 2/2] fix: bare except in exception_utils --- posthog/exception_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posthog/exception_utils.py b/posthog/exception_utils.py index f4142827..ad6cd33d 100644 --- a/posthog/exception_utils.py +++ b/posthog/exception_utils.py @@ -929,7 +929,7 @@ def _compile_patterns(patterns): for pattern in patterns: try: compiled.append(re.compile(pattern)) - except: + except Exception: pass return compiled