Problem
SyncTransport.request and AsyncTransport.request call method.upper() repeatedly inside the retry loop — once for the auth-sign, once for the httpx call, once inside sign_request itself, plus inside every debug log statement, multiplied across retry attempts and across both transports. Same string allocated each time for lowercase input. Cost per call is microseconds, but #262 specifically hoisted invariant header merging out of the retry loop for the same reason; this is the same pattern still latent.
Evidence
kalshi/_base_client.py:286-303 — multiple .upper() calls per attempt in the sync loop
for attempt in range(self._config.max_retries + 1):
auth_headers = self._auth.sign_request(method.upper(), sign_path) if self._auth else {}
...
logger.debug(
"Request: %s %s (attempt %d/%d)",
method.upper(),
...
)
...
response = self._client.request(
method=method.upper(),
...
)
kalshi/_base_client.py:504-535 — identical shape in AsyncTransport.request.
kalshi/auth.py:276 — sign_request also does method.upper() internally
message = ts_str + method.upper() + clean_path
Suggested fix
Normalize once at the top of request(): method = method.upper(). Reuse the normalized variable for the auth sign, httpx call, all log statements, and the retry-budget logs. Drop the redundant method.upper() inside sign_request (transports are now the only callers and always pre-normalize). Mirror the change in AsyncTransport.request and KalshiAuth.sign_request_async. Signing payload is byte-identical for any caller that passed lowercase.
Source
Round-3 independent audit (reviewer: performance).
Problem
SyncTransport.requestandAsyncTransport.requestcallmethod.upper()repeatedly inside the retry loop — once for the auth-sign, once for the httpx call, once insidesign_requestitself, plus inside every debug log statement, multiplied across retry attempts and across both transports. Same string allocated each time for lowercase input. Cost per call is microseconds, but#262specifically hoisted invariant header merging out of the retry loop for the same reason; this is the same pattern still latent.Evidence
kalshi/_base_client.py:286-303— multiple.upper()calls per attempt in the sync loopkalshi/_base_client.py:504-535— identical shape inAsyncTransport.request.kalshi/auth.py:276—sign_requestalso doesmethod.upper()internallySuggested fix
Normalize once at the top of
request():method = method.upper(). Reuse the normalized variable for the auth sign, httpx call, all log statements, and the retry-budget logs. Drop the redundantmethod.upper()insidesign_request(transports are now the only callers and always pre-normalize). Mirror the change inAsyncTransport.requestandKalshiAuth.sign_request_async. Signing payload is byte-identical for any caller that passed lowercase.Source
Round-3 independent audit (reviewer:
performance).