fix(types): close out remaining mypy errors (156 -> 0)
Walks the long tail of [union-attr], [arg-type], [assignment],
[return-value], [index] etc. The codebase is now mypy-clean from a
cold start.
Real bug fixes (would have manifested at runtime):
- base_event.py: ``b64encode(self.bytes)`` could be passed None when no
payload was attached; now defaults to empty bytes.
- proto/custom_proto.py: ``member_rank`` was annotated to return str
but actually returned int (delegates to ``member_level``); fix the
annotation. Drop a dead None-guard on ``follow_status`` (typed int
in v2, never None).
- errors.py:reset_time was annotated ``int`` but returned the raw
string from headers; coerce explicitly.
- ws_connect.py: websockets ``async for`` yields ``str | bytes``;
betterproto.parse only accepts bytes — coerce up front. Stop
mutating ``webcast_push_frame.payload`` from bytes to a parsed
object for log output (log the local var instead).
- ws_connect.py:_convert_proxy: guard against ``proxy.auth is None``
before indexing.
- web_base.py:set_session: coerce None cookie values to '' (httpx
Cookies.set rejects None).
- web_base.py:build_url: rewrite the URL-param parser so the
intermediate variable doesn't change type (was list-then-dict),
and use `str(url)` once at the top to handle httpx URL inputs.
- web_base.py: webcast_sign returns Optional[SignData] in the
envelope; raise UnexpectedSignatureError if missing instead of
silently downcasting.
- ws_client.py: insert assert-not-None after ``if not self.connected:
return`` guards (mypy can't follow property-based narrowing).
Same for ``self._ping_loop`` cleanup. Also coerce the ws_kwargs
proxy fallback through the already-Optional-narrowed ``self._ws_kwargs``.
- ws_client.py:connected returns ``bool`` not the Union of its parts.
- ws_client.py:send_ack: skip ack on the synthetic first iteration
where webcast_push_frame is None (sign-server initial response has
no push frame).
- fetch_video_data.py: assert _ffmpeg/process are set after the
``is_recording`` guard fires.
- fetch_room_id_live_html.py: ``room_data.get('roomId')`` returns
Optional[str]; raise if absent instead of declaring ``str`` and
silently propagating None.
- fetch_is_live.py: assert ``unique_id is not None`` after the
earlier "one of room_id/unique_id required" guard.
- client.py:parse_unique_id: accept ``str | int`` (matches the
constructor param) and stringify internally instead of forcing
callers to coerce.
- client.py:_is_user_id: coerce Optional[bool] to bool.
- client.py: assert ``self._room_id is not None`` after ``start()``
has resolved it (before passing to ``ws.connect`` and ConnectEvent).
Targeted ``# type: ignore`` for genuine third-party typeshed gaps
(not fixable without upstream typing changes):
- ws_connect.py: ``websockets.exceptions.InvalidStatusCode`` is
re-exported but not in the stub.
- proto/custom_proto.py:``betterproto.Message.to_pydict``'s ``casing``
arg is mistyped, and ``_betterproto`` classproperty assignment
isn't expressible.
- client.py:add_listener return-type tripping a TypeVar lint that's
cosmetic given pyee's generic shape.
Style:
- logger.py: drop redundant ``cast(int, ...)`` (the parent already
returns int).
- ws_utils.py:extract_websocket_options: widen ``headers`` to
``Mapping[str, str]`` so it accepts websockets/httpx Headers in
addition to plain dicts. I
isaackogan committed
1617c6b786eef3ad5da574aa04766aa1ae4df190
Parent: d73d74f