Commit 1cbc355
committed
sphinx-autodoc-argparse(refactor[typing]): register CLI roles via Sphinx.add_role
why: The five `cli-*` inline roles were registered via
`docutils.parsers.rst.roles.register_local_role`, which is typed
strictly for docutils-shaped callables and rejects Sphinx-style role
functions — each call needed `# type: ignore[arg-type]`.
`Sphinx.add_role(name: str, role: Any, override: bool = False)`
(`sphinx/application.py:1121`) accepts sphinx-shaped roles cleanly
and scopes registration to the Sphinx app rather than mutating
docutils process-global state.
what:
- Change `register_roles() -> None` to
`register_roles(app: Sphinx) -> None`
- Replace 5 `roles.register_local_role(..., ...) # type: ignore[arg-type]`
calls with `app.add_role(...)` — removes 5 ignores
- Drop `from docutils.parsers.rst import roles` import
- Add `TYPE_CHECKING` import of `sphinx.application.Sphinx`
- Expand docstring to explain the scope change; convert the doctest
to the standard `>>> register_roles # doctest: +ELLIPSIS` form
used elsewhere in the workspace
- Update the single caller in `exemplar.py:setup` to pass `app`
- Tighten `tests/ext/test_argparse_roles.py::test_register_roles`
to verify the five expected role names are registered, using a
local `_RoleRecorder` stub cast to `Sphinx`1 parent c94bc5a commit 1cbc355
3 files changed
Lines changed: 45 additions & 14 deletions
File tree
- packages/sphinx-autodoc-argparse/src/sphinx_autodoc_argparse
- tests/ext
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1364 | 1364 | | |
1365 | 1365 | | |
1366 | 1366 | | |
1367 | | - | |
| 1367 | + | |
1368 | 1368 | | |
1369 | 1369 | | |
1370 | 1370 | | |
| |||
Lines changed: 22 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
352 | | - | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
353 | 359 | | |
354 | 360 | | |
355 | 361 | | |
| |||
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
361 | 373 | | |
362 | 374 | | |
363 | | - | |
364 | | - | |
| 375 | + | |
| 376 | + | |
365 | 377 | | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
| |||
311 | 314 | | |
312 | 315 | | |
313 | 316 | | |
314 | | - | |
315 | | - | |
316 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
317 | 336 | | |
318 | 337 | | |
319 | 338 | | |
| |||
0 commit comments