Skip to content

[ci] [python-package] enforce 'numpydoc-validation' and 'pydoclint' checks - #7478

Merged
jameslamb merged 15 commits into
mainfrom
ci/pydoclint
Oct 25, 2026
Merged

jameslamb merged 15 commits into
mainfrom
ci/pydoclint

Conversation

@jameslamb

@jameslamb jameslamb commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Contributes to #7470

Proposes adding numpydoc-validation and pydoclint, 2 linters that enforce standardization and correctness of Python docstrings. These caught a few issues (like eval_{X,y} missing from the Dask docstrings.

Both are fast enough to not be noticeable.

I think they'll help a lot with consistency and standardization, and relieve a small bit of review burden.

Notes for Reviewers

I tried to choose configurations for these tools that as closely as possible match the project's current conventions. See inline comments below.

I've added this branch (temporarily) to readthedocs configuration.

Returns
-------
infos : tuple
tuple

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numpydoc-validation would really prefer that functions that return a single object not name the returned object. See https://numpydoc.readthedocs.io/en/latest/format.html#returns

list
Names of all parameters.
"""
""" # noqa: DOC105

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pydoclint directly compares the text of the type hint in the docstring to the text of the type hint in the code. This produces lots of false positives for lightgbm, for example where Python code has Path and the docstring has pathlib.Path.

I've requested a way to globally ignore checks, similar to ruff's "ignore" (jsh9/pydoclint#228 (comment)). But until then, I think it's not too bad to have these noqa comments everywhere. We don't add new public interfaces with new docstrings that often.

eval_init_score: Optional[List[_DaskCollection]] = None,
eval_metric: Optional[_LGBM_ScikitEvalMetricType] = None,
*,
categorical_feature: _LGBM_CategoricalFeatureConfiguration = "auto",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These had been in the docstrings inherited from the sklearn estimators but not actually written out in the code.

They were previously passed through **kwargs, and I'm just proposing promoting them to the signature:

  1. to help with tab completion and discoverability via help()
  2. to satisfy linter warnings about the "Parameters" section not matching the signature

@borchero borchero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked out pydocstyle? It's neat because you can integrate it directly with ruff; wouldn't need additional pre-commit hooks.

@jameslamb

Copy link
Copy Markdown
Member Author

This project already uses the pydocstyle ruff rules:

# pydocstyle
"D",

That didn't catch any of the issues caught by numpydoc-validation or pydoclint.

These are complementary tools.

There's some overlap between numpydoc-validation and pydoclint but they do also catch some different things.

I think we should have all 3 of these things enabled here. It would have avoided bugs like missing some docs updates when eval_y / eval_X were added in #6857

@jameslamb
jameslamb requested a review from borchero October 5, 2026 02:44

@borchero borchero left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, thanks for the explanation @jameslamb!

@jameslamb

Copy link
Copy Markdown
Member Author

Thanks very much for considering it and carefully reviewing!

@jameslamb
jameslamb merged commit 8852b92 into main Oct 25, 2026
61 checks passed
@jameslamb
jameslamb deleted the ci/pydoclint branch October 25, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants