writing-docstrings
Skill3 starsChanged 7 months agoMITView on GitHub
Use when writing or modifying any function, method, class, or source file in a repo using repo-hygiene — public API, internal helpers, and new files all require docstrings; only one-line lambdas and trivial accessors are excluded
1 other project uses a version of this.
Adopted by
Most recently taken up by
- reliable-coding-agents/reliable-pythontheir own version, first seen Sep 14, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- reliable-coding-agents/reliable-python★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository10 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- cleaning-existing-codebaseSkill
- gating-commitsSkill
- keeping-docs-freshSkill
- keeping-files-smallSkill
- orienting-to-repoSkill
- testing-new-codeSkill
- using-repo-hygieneSkill
- writing-commit-messagesSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 60
Every source file gets a header explaining its role.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing Docstrings
Overview
In a repo using repo-hygiene, docstrings on functions/classes and headers on source files are required. This OVERRIDES the default "no comments unless WHY is non-obvious" stance. The override exists because docstrings ARE the API contract — a future reader (human or agent) shouldn't have to read the body to know what to expect.
Core principle: A docstring earns its place by telling the reader something the signature does NOT tell them.
When To Use
- Writing a new function, method, or class
- Modifying a function's signature, return type, or contract
- Creating a new source file (write a header)
- Reviewing your own code before commit
What Earns a Docstring Its Place
A good docstring covers what the signature CAN'T:
- Contract — one-sentence promise, present tense
- Parameters — only those whose meaning isn't obvious from type/name
- Returns — only if non-obvious from the return type
- Raises / errors — failure modes the caller must handle
- Caveats — non-obvious behavior, side effects, performance, thread-safety
Skip anything the signature already conveys. The goal is information, not ceremony.
Before / After
❌ Restates the signature (worthless):
def parse_date(raw: str) -> datetime:
"""Parse a string and return a datetime."""
return datetime.strptime(raw, "%Y-%m-%d")❌ Empty ceremony:
def parse_date(raw: str) -> datetime:
"""
:param raw: the raw string
:returns: the parsed datetime
"""✅ Pins what the signature can't:
def parse_date(raw: str) -> datetime:
"""Parse a YYYY-MM-DD date. Raises ValueError on any other format."""
return datetime.strptime(raw, "%Y-%m-%d")File Headers
Every source file gets a header explaining its role. A header that just paraphrases the filename is worse than no header.
❌ Paraphrases filename:
"""user_repository.py — the user repository."""✅ Explains role + boundary:
"""Persistence layer for User aggregates.
Owns reads/writes to the `users` table. Callers should never use raw SQL
against this table — go through this module so audit logs stay consistent.
Domain type lives in domain/user.py.
"""A good header answers: what does this file own, what's the boundary, who calls it, what's a closely related file?
Narrow Exceptions
These don't need a docstring (the signature IS the spec):
- One-line lambdas / arrow functions
- Trivial accessors:
def name(self): return self._name - Single-expression private helpers under 3 lines
For everything else: if you can't think of a useful one-liner, the function probably does too much or is misnamed. Fix the function before skipping the docstring.
Quick Reference
| Language | Pattern |
| Python | """...""" after def/class; module header at top of file |
| TypeScript / JavaScript | JSDoc /** ... */ above function/class; top-of-file block |
| Go | // FuncName ... above declaration; // Package x ... at top |
| Rust | /// for items, //! for module-level |
| Java | Javadoc /** ... */ |
Mirror the repo's existing convention. If unclear, copy a well-documented file in the same language.
Common Mistakes
| Mistake | Fix |
| Restating the signature in prose | Cut. If the signature says it, the docstring is noise. |
| Documenting every param regardless of clarity | Only the ones whose meaning isn't obvious |
| File header paraphrases filename | Explain role + boundary + collaborators |
| "My default is no-comments" | This skill OVERRIDES that default. Intentional. |
| Skipping docs on "internal" helpers | Internal becomes public. Document the contract anyway. |
Red Flags — STOP
- "My default is no comments unless WHY is non-obvious" — that default does not apply in repo-hygiene repos
- About to ship a function with no docstring (outside the narrow exceptions)
- About to create a new file with no header
- Writing a docstring that just rephrases the function name — rewrite or you're adding noise
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

