Commit 7aa54e1
committed
chore(types): reduce pyrefly errors 130 → 21 (another 84% drop on top of 38%)
Continues the clean-up on fix/pyrefly-zero-errors. Combined with the
prior commit, the total reduction this branch is 205 → 21 errors (90%).
**NoReturn annotations for error re-raisers** (−22 errors): Slack's
`_handle_slack_error` and Google Chat's `_handle_google_chat_error`
always raise but were typed `-> None`/`-> Any`, so every `try/except`
that propagated through them showed as "missing return". Annotated
both as `NoReturn` to let pyrefly skip the downstream paths.
**Framework-agnostic `request` duck-typing** (−14 not-async errors):
`hasattr(request, "text") and callable(request.text)` narrows `Any`
to `object`, making `await request.text()` fail type-checking. Swapped
to `getattr(request, "text", None)` (preserves `Any`) plus
`inspect.isawaitable` for the sync-vs-async branch — same runtime
behavior, but properly typed. Applied across all 7 adapters that
duck-type aiohttp / FastAPI / Flask requests. Bonus: also fixes the
latent runtime bug where a sync `request.text` (Flask) would have
raised `TypeError: object is not awaitable`.
**Handler sync/async union** (−3 not-async errors): handler types are
`Callable[..., Awaitable[None] | None]` but `_run_handlers`,
`_direct_message_handlers`, and pattern handlers all `await`
unconditionally. Switched to `inspect.isawaitable` guards — same
runtime fix, same pragmatism about the TS port's `Promise<void> |
void` convention.
**Protocol conformance**:
- `_ChatSingleton` now `Protocol` (was plain class), so `Chat`
structurally satisfies it without an import cycle
- `ThreadImpl.channel` returns `Channel` (protocol) not `ChannelImpl`
so `ThreadImpl` passes the `Thread` protocol
- `set_state` param renamed `new_state` → `state` to match protocol
- `_ChannelImplConfigForChat` removed (duplicate of
`_ChannelImplConfigWithAdapter`)
- `ChatInstance` protocol now declares `handle_incoming_message`
(Discord adapter was calling it but the protocol didn't advertise it)
**TypedDict unions duck-typed via `cast`**: many adapters `.get()`
against TypedDict unions where the key only exists on some variants.
Added narrow `cast(...)` calls where the code has already
runtime-verified the variant via a `type` check.
**Card-element helpers**: helpers typed `dict[str, Any]` but callers
passed `CardChild` (union of TypedDicts). Added `cast("dict[str, Any]",
child)` at the `_render_child` / `_convert_child_to_widgets` branches
— the variant is already narrowed via `child.get("type")`.
**Misc**:
- `WhatsAppRawMessage.message` tightened `dict[str, Any]` → `WhatsAppInboundMessage`
- `GitHubAdapter._parse_issue_comment` / `_parse_review_comment`
param typed `GitHubRepository` instead of `dict[str, Any]`
- `_get_attachment_type` returns `Literal["audio","file","image","video"]`
- `is_encrypted_token_data` isn't a TypeGuard, so added an `assert`
to collapse the `Optional` before the attribute access
Baseline regenerated: 213 → 21 entries (90% of original errors gone).
`pyrefly check --baseline=.pyrefly-baseline.json` shows 0 new errors.
Validation:
- `uv run pytest tests/ -q` → 3359 passed, 11 skipped
- `uv run ruff check src/ tests/ scripts/` → clean
- `uv run ruff format --check src/ tests/ scripts/` → clean
- `uv run pyrefly check --baseline=.pyrefly-baseline.json` → 0 new1 parent 43c2cf0 commit 7aa54e1
21 files changed
Lines changed: 349 additions & 1516 deletions
File tree
- src/chat_sdk
- adapters
- discord
- github
- google_chat
- linear
- slack
- teams
- telegram
- whatsapp
- tests
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
380 | 382 | | |
381 | 383 | | |
382 | 384 | | |
383 | | - | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
384 | 390 | | |
385 | 391 | | |
386 | 392 | | |
| |||
1160 | 1166 | | |
1161 | 1167 | | |
1162 | 1168 | | |
1163 | | - | |
| 1169 | + | |
1164 | 1170 | | |
1165 | 1171 | | |
1166 | 1172 | | |
| |||
1257 | 1263 | | |
1258 | 1264 | | |
1259 | 1265 | | |
1260 | | - | |
| 1266 | + | |
1261 | 1267 | | |
1262 | 1268 | | |
1263 | 1269 | | |
| |||
1399 | 1405 | | |
1400 | 1406 | | |
1401 | 1407 | | |
1402 | | - | |
1403 | | - | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
1404 | 1413 | | |
1405 | 1414 | | |
1406 | 1415 | | |
1407 | | - | |
| 1416 | + | |
| 1417 | + | |
1408 | 1418 | | |
1409 | 1419 | | |
1410 | | - | |
1411 | | - | |
1412 | | - | |
1413 | | - | |
1414 | | - | |
1415 | | - | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
1416 | 1428 | | |
1417 | 1429 | | |
1418 | 1430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
| 120 | + | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
| 273 | + | |
| 274 | + | |
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
365 | 368 | | |
366 | 369 | | |
367 | 370 | | |
368 | | - | |
| 371 | + | |
369 | 372 | | |
370 | 373 | | |
371 | 374 | | |
| |||
409 | 412 | | |
410 | 413 | | |
411 | 414 | | |
412 | | - | |
| 415 | + | |
413 | 416 | | |
414 | 417 | | |
415 | 418 | | |
| |||
528 | 531 | | |
529 | 532 | | |
530 | 533 | | |
531 | | - | |
| 534 | + | |
532 | 535 | | |
533 | 536 | | |
534 | 537 | | |
| |||
889 | 892 | | |
890 | 893 | | |
891 | 894 | | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
892 | 898 | | |
893 | | - | |
| 899 | + | |
894 | 900 | | |
895 | 901 | | |
896 | 902 | | |
| |||
900 | 906 | | |
901 | 907 | | |
902 | 908 | | |
903 | | - | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
904 | 914 | | |
905 | 915 | | |
906 | | - | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
907 | 920 | | |
908 | 921 | | |
909 | 922 | | |
| |||
912 | 925 | | |
913 | 926 | | |
914 | 927 | | |
915 | | - | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
916 | 934 | | |
917 | 935 | | |
918 | 936 | | |
| |||
1069 | 1087 | | |
1070 | 1088 | | |
1071 | 1089 | | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
1075 | | - | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
1076 | 1098 | | |
1077 | 1099 | | |
1078 | 1100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
96 | 103 | | |
97 | 104 | | |
98 | 105 | | |
99 | | - | |
| 106 | + | |
100 | 107 | | |
101 | 108 | | |
102 | | - | |
| 109 | + | |
103 | 110 | | |
104 | 111 | | |
105 | | - | |
| 112 | + | |
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
110 | | - | |
| 117 | + | |
| 118 | + | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
115 | | - | |
116 | | - | |
| 123 | + | |
| 124 | + | |
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | 129 | | |
122 | | - | |
123 | | - | |
| 130 | + | |
| 131 | + | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
129 | 137 | | |
130 | | - | |
| 138 | + | |
131 | 139 | | |
132 | 140 | | |
133 | 141 | | |
| |||
233 | 241 | | |
234 | 242 | | |
235 | 243 | | |
236 | | - | |
| 244 | + | |
237 | 245 | | |
238 | 246 | | |
239 | 247 | | |
| |||
0 commit comments