Commit b8dcaa2
chore: annotate parser type_ arg as TypeAnnotation (#302)
## Summary
Fixes #301
Annotates the `type_` parameter on `list_parser`, `set_parser`,
`tuple_parser`, `dict_parser`, and `_get_parser` with
`fgpyo.util.types.TypeAnnotation` — the existing alias for the union of
runtime objects (`type | typing._GenericAlias | UnionType |
types.GenericAlias`) these parsers receive (`list[int]`, `int | None`,
`Literal["a", "b"]`, etc.). `TypeAlias` is the marker for declaring
aliases (`Foo: TypeAlias = ...`), so `TypeAnnotation` is the better fit
at this position.
**Annotation-only — runtime behavior is unchanged**, and the four public
parser entry points keep the same dispatch logic and return types.
Callers passing the kinds of annotation objects already exercised by
`tests/fgpyo/util/test_inspect.py` are unaffected.
With the more specific annotation in place, mypy can now check these
signatures meaningfully. That lets us drop five `# type:
ignore[comparison-overlap]` comments on the `typing.get_origin(...) is
list/set/tuple/dict/Literal` branches, and remove a vestigial `parser:
partial[type_]` forward declaration. A few internal calls (dict lookup
keyed by `type_`, `partial(type_)` in the constructor branches, and
calls into helpers in `types.py` that still take `Type[UnionType]` /
`Type[LiteralType]`) get narrow `# type: ignore[...]` comments — these
paths are runtime-safe today, and widening the `types.py` helper
signatures would let the ignores collapse together in a follow-up.
## Test plan
- \`uv run poe fix-and-check-all\` is clean (ruff, mypy, 842 pytest, 17
doctests).
- No new tests — the four public parsers' dispatch paths are already
covered in \`tests/fgpyo/util/test_inspect.py\`.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c627d50 commit b8dcaa2
2 files changed
Lines changed: 47 additions & 48 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
| 153 | + | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
210 | 210 | | |
211 | 211 | | |
212 | 212 | | |
213 | | - | |
| 213 | + | |
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
| 310 | + | |
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
323 | 322 | | |
324 | 323 | | |
325 | 324 | | |
| |||
328 | 327 | | |
329 | 328 | | |
330 | 329 | | |
331 | | - | |
| 330 | + | |
332 | 331 | | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
| 332 | + | |
338 | 333 | | |
339 | 334 | | |
340 | 335 | | |
| |||
346 | 341 | | |
347 | 342 | | |
348 | 343 | | |
349 | | - | |
| 344 | + | |
350 | 345 | | |
351 | | - | |
| 346 | + | |
352 | 347 | | |
353 | | - | |
| 348 | + | |
354 | 349 | | |
355 | | - | |
| 350 | + | |
356 | 351 | | |
357 | 352 | | |
358 | 353 | | |
| |||
365 | 360 | | |
366 | 361 | | |
367 | 362 | | |
368 | | - | |
| 363 | + | |
369 | 364 | | |
370 | 365 | | |
371 | 366 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
28 | 44 | | |
29 | 45 | | |
30 | 46 | | |
| |||
64 | 80 | | |
65 | 81 | | |
66 | 82 | | |
67 | | - | |
68 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
69 | 99 | | |
70 | 100 | | |
71 | 101 | | |
72 | | - | |
| 102 | + | |
73 | 103 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
0 commit comments