Skip to content

Add numpy-style docstrings to public API#32

Merged
MarcSkovMadsen merged 4 commits intomainfrom
copilot/add-numpy-style-docstrings
Feb 9, 2026
Merged

Add numpy-style docstrings to public API#32
MarcSkovMadsen merged 4 commits intomainfrom
copilot/add-numpy-style-docstrings

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

Core classes lacked meaningful docstrings, showing only brief one-liners in IDE tooltips without parameter details, examples, or usage guidance.

Changes

Enhanced 9 public classes:

  • SchemaSource, NodeType, EdgeType - Type definition helpers
  • NodeSpec, EdgeSpec - Graph element builders
  • Editor, JsonEditor, SchemaEditor - Property editors
  • ReactFlow - Main component

Enhanced 9 key methods:

  • Graph operations: add_node, remove_node, add_edge, remove_edge
  • Data updates: patch_node_data, patch_edge_data
  • NetworkX integration: to_networkx, from_networkx
  • Events: on

Format

Each docstring includes:

  • Concise summary line
  • Parameters section with types and defaults
  • Multiple practical examples
  • Cross-references (:class:, :meth:)
  • Return values and exceptions where applicable

Follows numpy convention for Sphinx compatibility and IDE tooltip rendering.

Example

Before:

class EdgeSpec(id: str, source: str, target: str, ...)
    Helper for constructing edge dictionaries.

After:

class EdgeSpec:
    """Builder for edge dictionaries with validation and type safety.
    
    Parameters
    ----------
    id : str
        Unique identifier for the edge. Must be unique within the graph.
    source : str
        ID of the source node where the edge originates.
    target : str
        ID of the target node where the edge terminates.
    ...
    
    Examples
    --------
    >>> edge = EdgeSpec(id="e1", source="n1", target="n2")
    >>> edge = EdgeSpec(id="e2", source="n2", target="n3", 
    ...                 style={"stroke": "#1976d2", "strokeWidth": 2})
    """

~35k characters of API documentation added. Enables Sphinx autodoc generation and improves IDE IntelliSense.

Original prompt

This section details on the original issue you should resolve

<issue_title>Please provide helpful docstrings</issue_title>
<issue_description>Many of the core classes lack useful docstrings. This makes it harder to use than it has to.

Please add proper numpy style docstrings that Sphinx can autogenerate reference docs from and that works well in VS Code tooltips. Please include one or more examples. Scope is public API.

Example

Image</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: MarcSkovMadsen <42288570+MarcSkovMadsen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add numpy style docstrings to core classes Add numpy-style docstrings to public API Feb 8, 2026
Copilot AI requested a review from MarcSkovMadsen February 8, 2026 21:47
Copy link
Contributor

@MarcSkovMadsen MarcSkovMadsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy. I've:

  • Skimmed through the PR
  • Done some sample checks
  • Had Claude Opus 4.6 locally review the PR
    • Create 51 tests covering the examples in the docstrings
    • Create 10 test apps covering the examples in the docstrings
    • Fix issues identified

@MarcSkovMadsen MarcSkovMadsen marked this pull request as ready for review February 9, 2026 05:45
>>> pn.extension()
>>>
>>> nodes = [
... NodeSpec(id="1", position={"x": 0, "y": 0}, label="Start").to_dict(),
Copy link
Contributor

@MarcSkovMadsen MarcSkovMadsen Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .to_dict is currently needed. But it should not be like that. See #19. Should be fixed later in separate pr.

... NodeSpec(id="2", position={"x": 200, "y": 0}, label="Process").to_dict(),
... NodeSpec(id="3", position={"x": 400, "y": 0}, label="End").to_dict(),
... ]
>>> edges = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .to_dict is currently needed. But it should not be like that. See #19. Should be fixed later in separate pr.

@MarcSkovMadsen MarcSkovMadsen merged commit aed7160 into main Feb 9, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please provide helpful docstrings

2 participants