Skip to content

PR: Improve Docstrings#1352

Merged
KelSolaar merged 26 commits intodevelopfrom
feature/docstrings
Jun 6, 2025
Merged

PR: Improve Docstrings#1352
KelSolaar merged 26 commits intodevelopfrom
feature/docstrings

Conversation

@KelSolaar
Copy link
Copy Markdown
Member

@KelSolaar KelSolaar commented Jun 4, 2025

Summary

This PR improves the docstrings by using Claude 4 via Claude Code.

A few observations:

  • This was expensive, more than anticipated: USD$265
    • Retrospectively, it would have been cheaper to get Claude Max for a month!
    • Cost was mostly driven by the fact I did a first test, which ( reverted because I did change our return value syntax, I deemed this undesirable .
    • The same prompt had to be executed multiple times because there are many instances where the guidelines were not fully respected
  • Guidelines respect as is typically the case with a LLM is often miss or hit
  • As I processed the docstrings sub-package by sub-package, the LLM took a slightly different approach every single time.

Was it worth it? I think so! Many small errors were fixed and the quality of the documentation has improved. However, for that particular task, I think it would be better to write a dedicated script that extracts the docstrings using the Python AST and process them by giving the object code and surrounding module code rather than having Claude Code doing the work itself. I was actually looking at whether we could implement a plugin on top of Ruff to do this or twist Pydocstyle's arm a bit!
I will work on something along those lines soon.

The prompt I used is as follows:


Task: Update docstrings in all Python modules within the current sub-package recursively to improve wording and clarity.

Processing Approach:

  • Think deeply
  • Use external tools only for listing Python modules, not for docstring processing
  • Process docstrings manually to ensure precision and compliance

Mandatory Requirements:

Content Standards:

  • Apply technical writing style conforming to scientific research standards
  • Use imperative mood (e.g., "Generate" not "Generates")
  • Replace "given" with "specified" where contextually appropriate
  • Make "luminance" and "lightness" lowercase unless sentence-initial or after colon
  • Preserve all existing docstring examples without modification
  • Add "Raises" section when exceptions are raised by the function
  • For docstrings beginning with "Return", consider contextually appropriate alternatives
  • Focus on clarity and precision in scientific context
  • Preserve all Sphinx markers (:math:, :param:, etc.) without modification
  • Maintain all reStructuredText emphasis markers around words, e.g., * in luminance, inRGB``, etc...
  • Preserve reStructuredText section headers exactly as written
  • Keep empty line between docstring and code

Restrictions:

  • Do NOT add parameter types (already documented via signature types)
  • Do NOT modify any object code outside docstrings
  • Do NOT edit module headers unless they contain clear errors
  • Do NOT process unit test modules
  • Do NOT change "colour" to "color" or "colourspace" to "colorspace"/"color space"
  • Do NOT change any reStructuredText section headers, i.e., all the headers underlined with - or = must be kept as is

Formatting:

  • Wrap all lines at exactly 79 characters

Verification Checklist:
Before completing each docstring update, verify:

  • All Sphinx markers preserved
  • Emphasis markers preserved
  • Section headers preserved
  • Imperative mood used consistently
  • "Raises" section added if exceptions present
  • No code modifications outside docstrings
  • British spelling preserved
  • 79-character line wrapping maintained

Preflight

Code Style and Quality

  • Unit tests have been implemented and passed.
  • Pyright static checking has been run and passed.
  • Pre-commit hooks have been run and passed.
  • [N/A] New transformations have been added to the Automatic Colour Conversion Graph.
  • [N/A] New transformations have been exported to the relevant namespaces, e.g. colour, colour.models.

Documentation

  • [N/A] New features are documented along with examples if relevant.
  • [N/A] The documentation is Sphinx and numpydoc compliant.

@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 99.342%. remained the same
when pulling b6ca4a6 on feature/docstrings
into a2d6971 on develop.

@nick-shaw
Copy link
Copy Markdown
Contributor

Sometimes the global change from "given" to "specified" makes things read a little oddly, e.g.

-        If the given specification doesn't exist in *Munsell Renotation System*
+        If the specified specification doesn't exist in *Munsell Renotation System*

@KelSolaar
Copy link
Copy Markdown
Member Author

Sometimes the global change from "given" to "specified" makes things read a little oddly, e.g.

-        If the given specification doesn't exist in *Munsell Renotation System*
+        If the specified specification doesn't exist in *Munsell Renotation System*

Good catch, fixed!

@KelSolaar KelSolaar merged commit a17e233 into develop Jun 6, 2025
31 of 32 checks passed
@KelSolaar KelSolaar deleted the feature/docstrings branch June 6, 2025 21:24
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.

3 participants