Commit dca49a7
authored
chore(typing): set up mypy and tighten the package to mypy --strict (#314)
The package ships a ``py.typed`` marker (advertising itself as typed to
downstream users) but nothing type-checked it. Add mypy and get a clean run.
Setup:
- [tool.mypy] in pyproject.toml: a lenient first-pass config
(ignore_missing_imports, target python_version 3.9), scoped to the
dataretrieval package.
- mypy<2 added to the [test] extra (<2 so it can still target 3.9).
- a type-check job in the CI workflow, parallel to the ruff lint job.
Fixes (mypy went from 78 errors to 0 on the tracked package):
- HTTPX_DEFAULTS annotated dict[str, Any] so **-splatting it into
httpx.get / httpx.AsyncClient type-checks -- cleared ~55 errors across
7 call sites at once.
- utils.py gains `from __future__ import annotations`: mypy (targeting
3.9) caught that the new `str | None` annotations there would be a
runtime error on 3.9, because this module -- unlike the rest of the
package -- lacked the future import.
- BaseMetadata.comment annotated `str | None` (was inferred `None`, which
rejected every subclass that assigns a comment string).
- _format_api_dates: accept Sequence[str | None] (covariant) so a
list[str] caller type-checks, and build the formatted list with an
early return so the final join sees list[str].
- _as_str_list: delegate to _normalize_str_iterable then wrap, so the
declared return type list[str] | None holds.
- _next_req_url: declare next_host / cur_host as `str | None`.
- ratings._search: build the query dict in a non-Optional local before
aliasing it to the loop's `params` (which toggles to None per page).
- nldi: drop the bool->str / Literal->str variable reuse; guard the basin
branch so feature_source / feature_id are non-None before get_basin.
- chunking: narrow the optional filter before _is_chunkable; fix a stale
`# type: ignore` error code.
The fixes are annotations and type-narrowing guards. The only runtime-visible
change is that nldi.search() now raises a clear ValueError up front when a
basin search is missing feature_source/feature_id, where the same condition
previously raised deeper inside get_basin. 259 tests pass across the affected
suites.1 parent c107fc9 commit dca49a7
14 files changed
Lines changed: 284 additions & 152 deletions
File tree
- .github/workflows
- dataretrieval
- waterdata
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
29 | 45 | | |
30 | 46 | | |
31 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | | - | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
77 | | - | |
| 79 | + | |
78 | 80 | | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | | - | |
| 86 | + | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
138 | | - | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
139 | 146 | | |
140 | 147 | | |
141 | 148 | | |
| |||
193 | 200 | | |
194 | 201 | | |
195 | 202 | | |
196 | | - | |
| 203 | + | |
197 | 204 | | |
198 | 205 | | |
199 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
25 | | - | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
32 | 36 | | |
33 | 37 | | |
34 | 38 | | |
35 | | - | |
| 39 | + | |
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
| |||
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | | - | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
116 | 120 | | |
117 | 121 | | |
118 | 122 | | |
119 | | - | |
| 123 | + | |
120 | 124 | | |
121 | 125 | | |
122 | 126 | | |
| |||
129 | 133 | | |
130 | 134 | | |
131 | 135 | | |
132 | | - | |
| 136 | + | |
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
| |||
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
165 | | - | |
166 | | - | |
167 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
168 | 175 | | |
169 | 176 | | |
170 | 177 | | |
171 | 178 | | |
172 | | - | |
| 179 | + | |
173 | 180 | | |
174 | 181 | | |
175 | 182 | | |
| |||
187 | 194 | | |
188 | 195 | | |
189 | 196 | | |
190 | | - | |
| 197 | + | |
191 | 198 | | |
192 | 199 | | |
193 | 200 | | |
| |||
285 | 292 | | |
286 | 293 | | |
287 | 294 | | |
288 | | - | |
| 295 | + | |
289 | 296 | | |
290 | 297 | | |
291 | 298 | | |
| |||
321 | 328 | | |
322 | 329 | | |
323 | 330 | | |
324 | | - | |
| 331 | + | |
325 | 332 | | |
326 | 333 | | |
327 | 334 | | |
| |||
336 | 343 | | |
337 | 344 | | |
338 | 345 | | |
339 | | - | |
| 346 | + | |
340 | 347 | | |
341 | 348 | | |
342 | 349 | | |
| |||
408 | 415 | | |
409 | 416 | | |
410 | 417 | | |
411 | | - | |
| 418 | + | |
412 | 419 | | |
413 | 420 | | |
414 | 421 | | |
| |||
428 | 435 | | |
429 | 436 | | |
430 | 437 | | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
431 | 442 | | |
432 | 443 | | |
433 | 444 | | |
| |||
458 | 469 | | |
459 | 470 | | |
460 | 471 | | |
461 | | - | |
| 472 | + | |
462 | 473 | | |
463 | 474 | | |
464 | 475 | | |
| |||
487 | 498 | | |
488 | 499 | | |
489 | 500 | | |
490 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
491 | 507 | | |
492 | 508 | | |
493 | 509 | | |
| |||
512 | 528 | | |
513 | 529 | | |
514 | 530 | | |
515 | | - | |
| 531 | + | |
516 | 532 | | |
517 | 533 | | |
518 | 534 | | |
| |||
0 commit comments