fix(types): silence mypy [misc] on intentional dual-base attr overlap

mypy emits two [misc] errors on the ProxyRateLimitError class line because
its two bases declare overlapping attributes with related-but-not-identical
annotations:

* status_code: int on starlette HTTPException vs. Literal[429] on openai's
  RateLimitError (every openai status-error subclass narrows it the same
  way and silences pyright with the same convention).
* headers: Mapping[str, str] | None on HTTPException vs. our Optional[
  Dict[str, str]] (the proxy hooks always carry a stringified dict).

Both narrowings are intentional and enforced at construction time. Add a
type: ignore[misc] with an inline explanation rather than relax the
annotations on the parent or change the wire-format guarantees.

LIT-2968

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-05-11 22:53:42 +00:00
parent 82f535d4d0
commit 0e427442a8
No known key found for this signature in database

View file

@ -61,7 +61,19 @@ def _coerce_message(detail: Any) -> str:
return str(detail)
class ProxyRateLimitError(HTTPException, RateLimitError):
# NOTE: mypy emits two `[misc]` errors on the class line below because the
# bases declare overlapping attributes with related-but-not-identical
# annotations:
# * `status_code` is `int` on starlette HTTPException but `Literal[429]` on
# openai.RateLimitError (every openai status-error subclass narrows it
# this way and silences pyright with the same convention).
# * `headers` is `Mapping[str, str] | None` on HTTPException; we narrow it
# to `Optional[Dict[str, str]]` on RateLimitError because we always carry
# a stringified dict.
# Both narrowings are intentional and handled at construction time — every
# instance always has status_code == 429 and a Dict-typed headers — so we
# silence the ATTR-overlap check rather than relax the annotations.
class ProxyRateLimitError(HTTPException, RateLimitError): # type: ignore[misc]
"""
A 429 raised by litellm's proxy-side rate limiting hooks.