Repository navigation
Commit 98ba77b
Add runblock examples to most public methods, fix bugs it surfaced
Public methods with a .. runblock:: pycon example: 21% -> 90% (13/62
-> 56/62). The remaining 6 are deliberate exclusions: remove(),
Edge.vertices(), BaseVertex.adjacent() are deprecated and not worth
featuring with a worked example; showgraph() genuinely opens a
browser window via webbrowser.open(), so actually executing it on
every doc build is a non-starter.
Adds matplotlib.sphinxext.plot_directive to the docs toolchain:
plot()/highlight_path()/highlight_edge()/highlight_vertex() now get
both a .. runblock:: (text I/O) and a .. plot:: (a real embedded
image, verified generating actual PNGs during the build), matching
the convention used elsewhere.
Two real bugs found and fixed while writing these examples, each
verified empirically:
- dotfile(): closed sys.stdout when called with the default
filename=None (the documented "print to console" behaviour) --
`if filename is None or isinstance(filename, str): f.close()`
closed sys.stdout itself in the None case, since f is sys.stdout
there. Any subsequent output in that process then crashed with
"ValueError: I/O operation on closed file." Reproduced with three
lines outside of Sphinx entirely. Fixed to only close a file this
method actually opened itself (the str case).
- highlight_vertex()'s docstring documented its parameter as `edge`
or Edge subclass when the real parameter is named `vertex`. Fixed,
and documented the previously-undocumented `alpha` parameter on
both highlight_edge() and highlight_vertex().
Also root-caused a sphinx_autodoc_typehints quirk that was silently
corrupting the doc build's reST structure for those same two methods:
a method that returns None, has a documented :param:/:type: field
list, and has a runblock afterward but no explicit :rtype:, gets an
auto-injected return-type annotation that collides with the runblock
directive boundary ("Explicit markup ends without a blank line").
Fixed by documenting :rtype: None explicitly wherever this pattern
occurs, rather than relying on the auto-injection.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>1 parent 6c24cfe commit 98ba77b
2 files changed
Lines changed: 468 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
0 commit comments