Skip to content

Comment and docstring conventions, and a pass applying them - #9

Merged
pingviini merged 3 commits into
mainfrom
chore/trim-output-rule-comments
Sep 15, 2026
Merged

pingviini merged 3 commits into
mainfrom
chore/trim-output-rule-comments

Conversation

@pingviini

@pingviini pingviini commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Comments and docstrings only. No behaviour change.

The convention, written down

AGENTS.md gains a Comments and docstrings section. The rules are written against this
codebase's habit of explaining at length, because that licence is what makes empty prose expensive:
a docstring opening with four lines that restate the signature teaches a reader to skim the
paragraph above it, which is where the reasons live.

Six rules: write what the code cannot say; say it once, where the decision lives; no :param: or
:return: that restates the signature, but keep every :raises:; cross-file pointers rot; bug
histories belong in the commit message; a docstring's first line says what the thing is for.

Applied to the comments added in #6

The same argument — why both format sets are published, so a mirror never reads "not pdf, therefore
image" — was made at OUTPUT_MODELS, again on ImageOutputRules.formats, again on
PdfOutputRules.formats, and again in the document builder. Now made once, where the sets are
defined.

The comment above reported in app/main.py ran ten lines: the rule, the bug behind it, the
Pydantic validator ordering that makes the bad case unreachable today, and what would happen if a
check moved into a field validator on files. Four lines remain — which error answers for
detail, code and rule, and why it is not simply errors[0]. Also gone: a comment naming
tests/test_output_rules.py from output_rules.py, and two test docstrings that restated the
assertions below them.

Applied to the docstrings

Twenty-four :param: lines existed; most restated the name and the annotation — :param renderer: The Typst renderer instance, :param count: The number of keys the caller sent. Removed where
they restate, kept where they add what the annotation cannot: that key reaches the caller's error
context, that source_bytes is already UTF-8, that _resource_limit_args returns empty when the
limit is unset, that a dsn of None disables Sentry. Every :raises: is kept — exceptions are
not in the signature, so those lines are the only statement of what escapes.

This pass covered app/render/renderer.py, app/api/routes.py and app/render/templates.py, which
held 20 of the 24. app/core/sentry.py and app/core/errors.py keep theirs, all of which carry
information.

Verification

uv run pytest (717 passed, 2 skipped, integration included), uv run ty check app scripts,
uv run ruff check . and make docs-build all pass.

The comments added with the output-rules document argued their case four
times over. Why both format sets are published was spelled out at
OUTPUT_MODELS, again on ImageOutputRules.formats, again on
PdfOutputRules.formats and again in the document builder; it is now made
once, where the sets are defined, and pointed at from the one field whose
purpose is not obvious from its name.

The handler's comment on which error answers for detail, code and rule
ran ten lines, most of it a history of the bug and a hypothetical about
moving a check into a field validator. Both belong to the commit that made
the change. What survives is the rule itself and why it is not errors[0].

Also drops a reference to the test file that reads the published lists —
a pointer that rots the moment the test moves — and trims two test
docstrings and the mirror's that restated what the assertions below them
already show.

No behaviour change: 717 passed, 2 skipped; ty and ruff clean.
…rings

Twenty-four :param: lines, and most restated the parameter name and its
annotation: "renderer: The Typst renderer instance", ":param count: The
number of keys the caller sent". A reader who needs those is reading the
signature anyway, and a docstring that opens with four of them teaches
them to skip the paragraph above, which is where this codebase keeps its
reasons.

Removed where they restate, kept where they add what the annotation
cannot — that key reaches the caller's error context, that source_bytes is
already UTF-8, that _resource_limit_args returns empty when the limit is
unset. Every :raises: is kept: exceptions are not in the signature, so
those lines are the only statement of what escapes.

AGENTS.md now carries the rules rather than leaving them to be rediscovered
per review. They are written against this codebase's habit of explaining at
length: the licence to do so is exactly what makes empty prose expensive.
@pingviini pingviini changed the title Trim the output-rule comments Comment and docstring conventions, and a pass applying them Sep 15, 2026
Thirteen docstrings of eight lines or more, read one at a time. Ten keep
every line: they carry what the code cannot say — why a failed prlimit
wrapper answers 422 to everyone and pages nobody, why --data must not be a
separate argv token, why measuring base64 without decoding may call a
whitespace payload too large rather than malformed. Length was never the
defect.

Three carried a sentence the docstring had already made:
_resource_limit_args stated the empty case in its summary and again in
:return:, _write_inline_files explained the escape check in a paragraph and
again in :param:, and validate_inline_file_key narrated that each check
below says what it rules out.

The scripts/ module docstrings name tests/test_examples.py, which the new
rule appeared to forbid. They are right and the rule was too broad: naming
a test as the consequence of ignoring an instruction is not the same as
naming one as evidence. The rule now says which is which.
@pingviini
pingviini merged commit 35621ab into main Sep 15, 2026
5 checks passed
@pingviini
pingviini deleted the chore/trim-output-rule-comments branch September 15, 2026 17:15
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.

1 participant