Title: Inconsistent typing for WebSocketMessage and WebSocketClient.run() callback in v2.8.0 · Issue #1022 · massive-com/client-python · GitHub
Open Graph Title: Inconsistent typing for WebSocketMessage and WebSocketClient.run() callback in v2.8.0 · Issue #1022 · massive-com/client-python
X Title: Inconsistent typing for WebSocketMessage and WebSocketClient.run() callback in v2.8.0 · Issue #1022 · massive-com/client-python
Description: Hi Massive team, I noticed an inconsistency in the websocket typing in Massive Python SDK v2.8.0. WebSocketMessage is currently defined as a NewType over a list of parsed event models: WebSocketMessage = NewType( "WebSocketMessage", List...
Open Graph Description: Hi Massive team, I noticed an inconsistency in the websocket typing in Massive Python SDK v2.8.0. WebSocketMessage is currently defined as a NewType over a list of parsed event models: WebSocketMes...
X Description: Hi Massive team, I noticed an inconsistency in the websocket typing in Massive Python SDK v2.8.0. WebSocketMessage is currently defined as a NewType over a list of parsed event models: WebSocketMes...
Opengraph URL: https://github.com/massive-com/client-python/issues/1022
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent typing for WebSocketMessage and WebSocketClient.run() callback in v2.8.0","articleBody":"Hi Massive team,\n\nI noticed an inconsistency in the websocket typing in Massive Python SDK v2.8.0.\n\n`WebSocketMessage` is currently defined as a `NewType` over a list of parsed event models:\n\n```python\nWebSocketMessage = NewType(\n \"WebSocketMessage\",\n List[\n Union[\n EquityAgg,\n CurrencyAgg,\n EquityTrade,\n ...\n ]\n ],\n)\n```\n\nHowever, `WebSocketClient.run()` is typed as accepting a callback of:\n\n```python\nCallable[[List[WebSocketMessage]], None]\n```\n\nThis effectively makes the callback parameter type a nested list-like structure:\n`List[WebSocketMessage]`, while `WebSocketMessage` itself already represents a list\nof parsed websocket events.\n\nThis causes type checkers such as Pyright/Pylance to reject handlers like this:\n\n```python\ndef handle_msg(messages: WebSocketMessage) -\u003e None:\n for message in messages:\n if isinstance(message, EquityAgg):\n ...\n```\n\nwith an error similar to:\n\n```text\nArgument of type \"(messages: WebSocketMessage) -\u003e None\" cannot be assigned to parameter \"handle_msg\"\nType \"(messages: WebSocketMessage) -\u003e None\" is not assignable to type \"(List[WebSocketMessage]) -\u003e None\"\n```\n\nThere also seems to be a related inconsistency in the parser:\n\n```python\ndef parse_single(...) -\u003e Optional[WebSocketMessage]:\n parsed = model_class.from_dict(data)\n return cast(WebSocketMessage, parsed)\n```\n\nAt runtime, `parsed` is a single event object such as `EquityAgg`, not a list. Then\n`parse()` returns `List[WebSocketMessage]`.\n\nSo there appear to be two possible fixes:\n\n1. If `WebSocketMessage` is intended to mean a single parsed event, redefine it as\n a union of event model types, not a list.\n2. If `WebSocketMessage` is intended to mean a batch of parsed events, then `run()`\n should accept `Callable[[WebSocketMessage], None]`, and `parse_single()` should\n not cast individual event objects to `WebSocketMessage`.\n\nBased on the current runtime behavior, option 1 seems more natural:\n\n```python\nWebSocketMessage = NewType(\n \"WebSocketMessage\",\n Union[\n EquityAgg,\n CurrencyAgg,\n EquityTrade,\n ...\n ],\n)\n```\n\nor alternatively, using a type alias instead of `NewType`:\n\n```python\nWebSocketMessage = Union[\n EquityAgg,\n CurrencyAgg,\n EquityTrade,\n ...\n]\n```\n\nThen these signatures would make sense:\n\n```python\ndef parse_single(...) -\u003e Optional[WebSocketMessage]: ...\ndef parse(...) -\u003e List[WebSocketMessage]: ...\n\ndef run(\n self,\n handle_msg: Callable[[List[WebSocketMessage]], None] | Callable[[str | bytes], None],\n close_timeout: int = 1,\n **kwargs: Any,\n) -\u003e None: ...\n```\n\nOne smaller typing improvement: `run()` currently leaves `**kwargs` unknown for\nPyright/Pylance. Annotating it as `**kwargs: Any` and adding `-\u003e None` would avoid\n\"partially unknown\" warnings.\n\nThanks.\n","author":{"url":"https://github.com/aircozy","@type":"Person","name":"aircozy"},"datePublished":"2026-06-02T13:45:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1022/client-python/issues/1022"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:374d381b-1240-caab-cfc5-c25cbd304fe4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 810C:39B130:10EEC:15C23:6A4C8E78 |
| html-safe-nonce | cd69590c469a28708f24b04703b5889f2dd09b1ebe631885390019b051bde7bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTBDOjM5QjEzMDoxMEVFQzoxNUMyMzo2QTRDOEU3OCIsInZpc2l0b3JfaWQiOiI2OTQ4OTkzOTkzMDY1NDY4MDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1d04df68e45113a247b97b55ddbf764096f86f2b1dba66abdb09c83268275ed9 |
| hovercard-subject-tag | issue:4571958878 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/massive-com/client-python/1022/issue_layout |
| twitter:image | https://opengraph.githubassets.com/909da023abb03ae2f91ca01a959672dcf2db7fccc757e93d6c027d7fa6d2b174/massive-com/client-python/issues/1022 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/909da023abb03ae2f91ca01a959672dcf2db7fccc757e93d6c027d7fa6d2b174/massive-com/client-python/issues/1022 |
| og:image:alt | Hi Massive team, I noticed an inconsistency in the websocket typing in Massive Python SDK v2.8.0. WebSocketMessage is currently defined as a NewType over a list of parsed event models: WebSocketMes... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aircozy |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| go-import | github.com/massive-com/client-python git https://github.com/massive-com/client-python.git |
| octolytics-dimension-user_id | 191946194 |
| octolytics-dimension-user_login | massive-com |
| octolytics-dimension-repository_id | 216660192 |
| octolytics-dimension-repository_nwo | massive-com/client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 216660192 |
| octolytics-dimension-repository_network_root_nwo | massive-com/client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7a2dede45637df6b92ddcfe2a557e67d4b5854ae |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width