-
Notifications
You must be signed in to change notification settings - Fork 69
fix: improve strict public API types #685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
marandaneto
wants to merge
5
commits into
main
Choose a base branch
from
fix/strict-public-api-types-559
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
35f06ff
fix: improve strict public API types
marandaneto d408314
address pr review feedback
marandaneto 5035d13
ci: add strict type smoke test
marandaneto 37cd471
address pr review feedback
marandaneto 9bd5b40
address pr review feedback
marandaneto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'pypi/posthog': patch | ||
| --- | ||
|
|
||
| Improve strict Pyright coverage for public PostHog APIs. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| PYTHON_VERSION="${PYTHON_VERSION:-3.11}" | ||
| tmp="$(mktemp -d)" | ||
| trap 'rm -rf "$tmp"' EXIT | ||
|
|
||
| python -m venv "$tmp/.venv" | ||
| "$tmp/.venv/bin/python" -m pip install --quiet --upgrade pip | ||
| "$tmp/.venv/bin/python" -m pip install --quiet . pyright | ||
|
|
||
| cat > "$tmp/strict_posthog_types.py" <<'PY' | ||
| # pyright: strict | ||
| import atexit | ||
|
|
||
| import posthog | ||
| from posthog import FlagValue, Posthog | ||
|
|
||
| client = Posthog("phc_test") | ||
| atexit.register(client.shutdown) | ||
|
|
||
| flag_value: FlagValue | None = client.get_feature_flag("flag", "user") | ||
| all_flags: dict[str, FlagValue] | None = posthog.get_all_flags("user") | ||
| enabled: bool | None = posthog.feature_enabled("flag", "user") | ||
| payload: object | None = client.get_feature_flag_payload("flag", "user") | ||
|
|
||
| _ = (flag_value, all_flags, enabled, payload) | ||
| PY | ||
|
|
||
| "$tmp/.venv/bin/python" - <<'PY' > "$tmp/public_api_access.py" | ||
| import inspect | ||
|
|
||
| import posthog | ||
| from posthog import Posthog | ||
|
|
||
| print("# pyright: strict") | ||
| print("import posthog") | ||
| print("from posthog import Posthog") | ||
| print('client = Posthog("phc_test")') | ||
|
|
||
| for name, obj in inspect.getmembers(Posthog): | ||
| if name.startswith("_"): | ||
| continue | ||
| if inspect.isfunction(obj) or inspect.ismethoddescriptor(obj): | ||
| print(f"client_{name} = client.{name}") | ||
|
|
||
| for name, obj in inspect.getmembers(posthog): | ||
| if name.startswith("_") or name.startswith("inner_"): | ||
| continue | ||
| if inspect.isfunction(obj): | ||
| print(f"module_{name} = posthog.{name}") | ||
| PY | ||
|
|
||
| cat > "$tmp/pyrightconfig.json" <<JSON | ||
| { | ||
| "typeCheckingMode": "strict", | ||
| "pythonVersion": "$PYTHON_VERSION", | ||
| "venvPath": "$tmp", | ||
| "venv": ".venv", | ||
| "reportMissingTypeStubs": "error", | ||
| "reportPrivateImportUsage": "error", | ||
| "reportUnknownArgumentType": "error", | ||
| "reportUnknownMemberType": "error", | ||
| "reportUnknownVariableType": "error" | ||
| } | ||
| JSON | ||
|
|
||
| cd "$tmp" | ||
| "$tmp/.venv/bin/python" -m pyright strict_posthog_types.py public_api_access.py |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.