Enable the D417 Ruff rule and stop repeating type annotations in docstrings - #104
Merged
Conversation
D417 was suppressed because it reported 9 functions with undocumented parameters. Eight of those were false positives: no pydocstyle convention was configured, so Ruff parsed the `Parameters` + dashed-underline headers as NumPy sections, found no NumPy-formatted entries inside them, and reported every argument as undocumented. The docstring bodies are Google-style throughout, and docs/source/conf.py already sets napoleon_google_docstring = True, so pin the convention to google. That drops D417 from 9 findings to 1, where numpy would leave 8. The only rules the convention retires are D400, whose check is subsumed by the still-active D415, and the cosmetic D413. Convert the 49 dashed section headers to Args:/Returns:/Raises: and fill in the parameters that were genuinely undocumented once the sections parsed: omit_bboxes, gdf, auto_clean_csv, tolerance, three in process_parallel, and dem_ndv/min_confidence_level/min_bathy_confidence in validate_dem, whose wording follows the CLI help for the matching options. process_parallel also documented a "kwargs_lists" parameter that the signature spells kwargs_list. Only docstrings change here; every edited file was checked to have an identical AST once docstring constants are blanked.
Google's style guide asks for a type in an Args: entry only when the
signature does not annotate the parameter, and docs/source/conf.py loads
sphinx_autodoc_typehints with always_document_param_types = True, so an
annotated parameter already renders its type and default from the
signature. A hand-written type is therefore a duplicate that can, and did,
contradict the signature: 28 of the 73 annotated parameters carrying a type
disagreed with their annotation, nearly all of them missing a "| None"
added to the signature later.
Drop the type from all 73 annotated parameters and keep it, in Google
"name (type):" form, for the 13 that have no annotation.
Three problems in the same docstrings kept Sphinx from rendering these
sections at all, and are fixed here too:
- 30 entries were NumPy-shaped ("name : type" with the prose on the
following line). Napoleon splits on the first colon, so the type was
rendered as the opening words of the description.
- 22 section bodies sat flush with their Args:/Returns:/Raises: header
rather than indented under it. D417 accepts that; napoleon reads the
section as empty and emits no parameters.
- 3 Raises: blocks put the exception name on its own line.
Across the files touched here, the number of parameters napoleon renders as
real :param: fields goes from 50 to 124, with no documented parameter left
unrendered and no description still opening with a bare type.
Docstrings only; each edited file has an identical AST once docstring
constants are blanked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Progress on #40. Two commits, each independently green.
1. Enable D417 and set the Google docstring convention
D417 (
undocumented-param) was suppressed because it reported nine functions with undocumented parameters. Eight of those were false positives. No pydocstyle convention was configured, so Ruff parsed theParameters+ dashed-underline headers as NumPy sections, found no NumPy-formatted entries inside, and reported every argument as undocumented.The docstring bodies are Google-style throughout, and
docs/source/conf.pyalready setsnapoleon_google_docstring = True, so the convention is pinned togoogle. That takes D417 from 9 findings to 1;numpywould have left 8. The only rules the convention retires areD400, whose check is subsumed by the still-activeD415, and the cosmeticD413.The 49 dashed section headers become
Args:/Returns:/Raises:, and the parameters that were genuinely undocumented — visible only once the sections parsed — are filled in:omit_bboxes,gdf,auto_clean_csv,tolerance, three inprocess_parallel, anddem_ndv/min_confidence_level/min_bathy_confidenceinvalidate_dem, worded from the CLI help for the matching options.D417 also caught a real documentation bug:
process_paralleldocumented akwargs_listsparameter that the signature spellskwargs_list.Ignore list: 57 → 56.
2. Let annotations be the only source of parameter types
Google's style guide asks for a type in an
Args:entry only when the signature does not annotate the parameter, andconf.pyloadssphinx_autodoc_typehintswithalways_document_param_types = True— so an annotated parameter already renders its type and default from the signature. A hand-written type is a duplicate that can contradict it, and did:The drift was almost entirely a
| Noneadded to a signature and never to the prose —validate_dem'soutput_dirclaimedstragainst an annotation ofstr | None. The type is dropped from all 73 annotated parameters and kept, in Googlename (type):form, for the 13 without annotations.Three problems in the same docstrings were stopping Sphinx from rendering these sections at all, and are fixed here too:
name : type, prose on the next line). Napoleon splits on the first colon, so the type rendered as the opening words of the description.Raises:blocks put the exception name on its own line.Verification
Running every docstring through napoleon with this repo's own
conf.pysettings, counting parameters emitted as real:param:fields in the files touched here::paramfieldsmainNo documented parameter fails to render, and no rendered description still opens with a bare type.
ruff check,ruff formatand the fullpreksuite pass at both commits. No code changed anywhere — every edited file was verified to produce an identical AST once docstring constants are blanked, with docstring counts unchanged.🔍 Docs preview: https://ivert--104.org.readthedocs.build/en/104/