fix: improve strict public API types#685
Open
marandaneto wants to merge 5 commits into
Open
Conversation
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
posthog/__init__.py:62-67
`FlagValue` is imported without the `as FlagValue` explicit re-export form, so strict Pyright will still raise `reportPrivateImportUsage` when downstream users write `from posthog import FlagValue` to annotate variables holding the return value of `get_feature_flag()` or `get_all_flags()`. Every other intentionally public type in this block uses the `X as X` pattern (`BeforeSendCallback as BeforeSendCallback`, `FeatureFlag as FeatureFlag`); `FlagValue` should match.
```suggestion
from posthog.types import (
BeforeSendCallback as BeforeSendCallback,
FeatureFlag as FeatureFlag,
FlagValue as FlagValue,
FlagsAndPayloads,
)
```
Reviews (1): Last reviewed commit: "fix: improve strict public API types" | Re-trigger Greptile |
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
Contributor
posthog-python Compliance ReportDate: 2026-06-19 14:10:23 UTC ✅ All Tests Passed!45/45 tests passed Capture Tests✅ 29/29 tests passed View Details
Feature_Flags Tests✅ 16/16 tests passed View Details
|
79c9d47 to
60c6a4f
Compare
60c6a4f to
35f06ff
Compare
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
marandaneto
commented
Jun 19, 2026
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
posthog/__init__.py:6
`ID_TYPES` is newly added to the public API snapshot by this PR and appears in public function signatures, but it is imported without the explicit `X as X` re-export form. Under strict Pyright with `reportPrivateImportUsage: error` (which the new smoke-test config enforces), `from posthog import ID_TYPES` would still fail. The PR fixed exactly this pattern for `FlagValue` (`FlagValue as FlagValue`) and `FeatureFlag` (`FeatureFlag as FeatureFlag`), so `ID_TYPES` should receive the same treatment. Note that the smoke-test only checks `from posthog import FlagValue, Posthog`, so this gap is not currently caught by CI.
```suggestion
from posthog.args import ID_TYPES as ID_TYPES, ExceptionArg, OptionalCaptureArgs, OptionalSetArgs
```
### Issue 2 of 2
.github/scripts/check_strict_types.sh:10
`pyright` is installed at its latest released version on every CI run. A new pyright release with tighter checks (or changed defaults) can silently break the job or, conversely, loosen it. Pinning to a known-good version keeps the check stable and makes upgrades a deliberate action. The version can be reviewed and bumped periodically.
```suggestion
"$tmp/.venv/bin/python" -m pip install --quiet . "pyright==1.1.399"
```
Reviews (2): Last reviewed commit: "address pr review feedback" | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
Strict Pyright users could still hit partially unknown types when accessing public PostHog APIs, even after the issue-specific
Posthog.shutdownpath was fixed.Fixes #559.
💚 How did you test it?
/batch/backend contract inrust/capture/src/v0_request.rsandrust/common/types/src/event.rs. The SDK intentionally keeps some wrapper timestamp types stricter than the backend accepts.python -m mypy --config-file mypy.ini posthog/client.py posthog/__init__.pyuv run ruff check posthog/client.py posthog/__init__.pyuv run --extra dev python .github/scripts/check_public_api.pyuv run --extra test pytest posthog/test/test_feature_flag.py posthog/test/test_feature_flag_result.py posthog/test/test_module.py::TestModule::test_flush.github/scripts/check_strict_types.shStrict type smokejob that runs.github/scripts/check_strict_types.sh. The script installs the package into a temporary downstream venv, runs strict Pyright against representative public API usage, and checks all public client/module function member access for unknown types.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
An AI coding agent investigated the strict typing gaps around #559, identified remaining Pyright
Unknowntypes on public APIs, and made a typing-only fix. The changes focus on explicit public signatures inposthog.client.Clientand the module-level wrappers inposthog.__init__, plus a patch changeset for release notes and a strict downstream Pyright smoke check in CI.