Repository navigation
Add runblock examples to most public methods, fix bugs it surfaced - #11
Merged
Merged
Conversation
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>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11 +/- ##
=======================================
Coverage 85.20% 85.20%
=======================================
Files 2 2
Lines 750 750
=======================================
Hits 639 639
Misses 111 111 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Public methods with a
.. runblock:: pyconexample: 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 viawebbrowser.open(), so actually executing it on every doc build is a non-starter.Adds
matplotlib.sphinxext.plot_directiveto 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 in the ecosystem.Two real bugs found and fixed while writing these examples, each verified empirically:
dotfile()closedsys.stdoutwhen called with the defaultfilename=None(the documented "print to console" behaviour) --if filename is None or isinstance(filename, str): f.close()closedsys.stdoutitself in theNonecase, sincefissys.stdoutthere. Any subsequent output in that process then crashed withValueError: 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 (thestrcase).highlight_vertex()'s docstring documented its parameter asedge/Edge subclasswhen the real parameter is namedvertex. Fixed, and documented the previously-undocumentedalphaparameter on bothhighlight_edge()andhighlight_vertex().Also root-caused a
sphinx_autodoc_typehintsquirk that was silently corrupting the doc build's reST structure for those same two methods: a method that returnsNone, 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: Noneexplicitly wherever this pattern occurs, rather than relying on the auto-injection.Test plan
RUNBLOCK-ERROR, noExplicit markupwarnings, no new warning categories vs. the pre-existing baseline.. plot::blocks confirmed generating real PNG images during the build