Reviewer · Documentation
Keep comments synchronized
Comments and docstrings must stay accurate and in sync with the code they describe, since misleading documentation is worse than no documentation. Apply this in three common scenarios:
Comments and docstrings must stay accurate and in sync with the code they describe, since misleading documentation is worse than no documentation. Apply this in three common scenarios:
-
Remove or update orphaned section comments. When code under a header comment is moved or deleted, delete the comment too, or update it to reflect what’s actually there. A header like
# System shutdown / rebootleft with no entries beneath it (because the logic moved into_BASH_COMMAND_WORDS) wrongly implies that category is still handled right there, misleading the next reader auditing coverage. -
Document the real scope of parameters, especially safety/correctness flags. If a flag like
strict=Trueonly guarantees strictness for an object’s own attributes and nested mixin values, but not for whatever a foreign object’s ownto_dict()returns, state that explicitly in the docstring’sArgssection. Don’t let the implementation’s actual guarantees diverge silently from what a reader would assume from the name or summary. -
Explain intentionally “unused” code. If a method (e.g.,
_read_shared_state) has no production call sites but is kept on purpose (as an audit-log accessor, test hook, or public API), add a short docstring note saying so. This prevents future contributors or linters from flagging and removing it as dead code.
As a rule: whenever you move, remove, or constrain behavior in code, grep for and update any comment or docstring that references it, and whenever you leave something that looks incomplete, unused, or surprising, add a brief note explaining why.