polish: Wave 5 backlog — transport perf, config knobs, docs, CI hardening#141
Conversation
Code Review — Wave 5 Polish (#141)Five isolated, low-risk items. Overall the changes are clean and well-scoped. A few things worth addressing before merge: F-R-04 —
|
| Item | Status | Blocker? |
|---|---|---|
urlparse cache |
✅ Clean | — |
http2/limits config |
AsyncTransport tests; limits forwarding not verified |
Yes (test coverage) |
ws docstring |
✅ Clean | — |
| Shred PEM | ✅ Correct; shred --zero optional improvement |
No |
| Sigstore attestations | ✅ Correct; pre-existing SHA-pin gap | No |
The test gaps on AsyncTransport and the limits→httpx forwarding assertion are the ones I'd want addressed before merge. Everything else is solid.
`urlparse(self._config.base_url).path` was recomputed on every request inside both SyncTransport.request and AsyncTransport.request retry loops. `base_url` is immutable on a frozen KalshiConfig, so cache the parsed path once in `__init__` and reuse it. Saves ~0.35 µs per request — trivial on its own, free correctness win. Refs #106 (F-R-04) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Add two opt-in tuning knobs for power users: * ``http2: bool = False`` — enable HTTP/2 for REST. Off by default for back-compat. Requires the ``h2`` extra (``pip install httpx[http2]`` or ``pip install h2``). * ``limits: httpx.Limits | None = None`` — pass-through for httpx connection-pool tuning. ``None`` (default) preserves httpx defaults. Both flags are forwarded to httpx.Client and httpx.AsyncClient at construction. Default behavior is unchanged, so this is non-breaking. Refs #106 (F-R-15) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
``.ws`` returns a new ``KalshiWebSocket`` instance on every access. That's intentional (each property hit is independent), but the behavior is a foot-gun for the callback API — ``@client.ws.on(...)`` registers against an instance that's immediately thrown away. Make the property docstring spell out: * each access returns a fresh instance; * capture to a local if you need shared state (callbacks, subs); * sync ``KalshiClient`` does not expose ``.ws`` at all. Refs #106 (F-N-10) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The integration-nightly job writes the Kalshi private key to ``$RUNNER_TEMP`` with ``chmod 600`` but never removes it. Hosted runners are ephemeral so impact is low today, but the cleanup matters the moment anyone flips to self-hosted runners. Add an ``if: always()`` step that runs ``shred -u`` (falling back to ``rm -f``) on the key file regardless of test outcome. Refs #106 (F-O-11) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
``pypa/gh-action-pypi-publish`` supports generating and uploading PEP 740 sigstore attestations alongside the release artifacts when ``attestations: true`` is set. PyPI exposes them on the project page so downstream verifiers can confirm the artifacts came from this exact workflow run. Also add the ``attestations: write`` permission required for the action to sign via the GitHub OIDC issuer. Refs #106 (F-O-12) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sibling commit ec68e9d (this branch) added KalshiConfig.http2 and KalshiConfig.limits but didn't update CHANGELOG. Adding the Added entry retroactively under [Unreleased] so the release-cut summary captures it. Refs #106 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
21bade9 to
ae36045
Compare
Code Review — Wave 5 Polish (#141)
OverviewFive tightly-scoped changes: a micro-perf fix, two new config knobs, a lifecycle docstring, and two CI hardening steps. The scope discipline is excellent — the deferred-items table especially. No complaints there. What's solid
Issues1. Tests verify config round-trip, not httpx forwardingThe two new forwarding tests check The comment in the test acknowledges the limitation ("httpx exposes http2 via the private # Inspect the constructed client via its public interface
transport = SyncTransport(test_auth, KalshiConfig(http2=False))
# httpx.Client.is_closed is public; _transport._pool._http2 is semi-private but stable
assert transport._client._transport._pool._http2 is FalseOr use with patch("httpx.Client") as mock_client:
SyncTransport(test_auth, KalshiConfig(http2=True))
_, kwargs = mock_client.call_args
assert kwargs["http2"] is TrueEither approach would catch a regression where the kwarg is accidentally dropped. Future: worth a follow-up to strengthen these two tests. 2. No
|
Summary
Wave 5 #106 — 5 small polish items from the umbrella backlog. Items picked are low-risk, single-purpose, and stayed clear of Wave 3/4 (
kalshi/ws/) and sibling #90 (kalshi/models/) territory.9c8b7e9urlparse(base_url).pathonce per transport instead of re-parsing on every requestkalshi/_base_client.pyec68e9dKalshiConfig.http2: bool = FalseandKalshiConfig.limits: httpx.Limits | None = None. Non-breaking; defaults preserve existing behaviorkalshi/config.py,kalshi/_base_client.py,tests/test_config.py(+4 tests)40606c6AsyncKalshiClient.wslifecycle docstringkalshi/async_client.pyea4eb0e.github/workflows/integration-nightly.ymla972cbd.github/workflows/release.ymlAddedentry forhttp2/limitsconfig knobsItems deferred (with rationale)
kalshi/models/*is sibling-branch territory (Type-annotation drift: size/count fields useDollarDecimalinstead ofFixedPointCount#90)._to_decimal_*): explicitly covered by Type-annotation drift: size/count fields useDollarDecimalinstead ofFixedPointCount#90.yield fromvsreturn self._list_all): already standardized by Wave 2 Test coverage:_list_allmax_pagescap + expose on public*_all()methods #98; no occurrences remain.kalshi/ws/Wave 3/4 territory.kalshi/ws/territory.The agent's first 5 commits landed on the parent repo's local
mainby mistake (Bash CWD reset between calls — same trap as Wave 2 #102). The agent cherry-picked all 5 to the proper branch in its worktree, then surgically rewoundrefs/heads/mainback toorigin/main. Verified clean before push.Test plan
uv run ruff check .cleanuv run mypy kalshi/clean (strict)a972cbd) won't actually run until next tagea4eb0e) effective on next nightly cronRefs #106