Open drammock opened 5 months ago
In scikit-learn, we have a tests to enforce constraints on the docstring parameters:
I never pushed for a dynamic way to fill in the docstrings, because of the issues with static analyzers.
In scikit-learn, we have a tests to enforce constraints on the docstring parameters:
Thanks @thomasjpfan. We have similar tests in MNE-Python (probably we copied ours from sklearn) but like your tests, they don't enforce much about the content of the parameter descriptions, mostly just ensuring that they exist and that they come in the same order as the function signature.
I never pushed for a dynamic way to fill in the docstrings, because of the issues with static analyzers.
It's seeming like the only option that both works with static analysis and also preserves consistency across the API would be to go back to having our docstrings all hard-coded in the source files, maintaining a mapping somewhere saying "the param description for picks
(or axes
or whatever) should be identical across this list of functions", and then asserting that in a test.
To be honest, I'd prefer almost anything over doccer expansion at this point. Besides static analyzers, the benefit of being able to just read docstrings in the source cannot be overstated.
I am also not a fan of "docstrings with holes in them" aka things that aren't fully readable by opening the source file in a simple text editor.
A random idea: maybe generating the docstring once and writing it to the source file is something to investigate? Could be a tool that you run on a new class/function. For example to generate a docstring for scipy.foo.bar
you'd run python generate_docstring.py scipy.foo.bar
and it will spit out a (more or less) ready to go string that people can add to the code.
That way the initial docstring would be consistent with the rules.
You could even imagine something like python generate_docstring.py --check scipy.foo.bar
which creates the docstring and diff's it with what is actually present. And then extend it even further using something like libcst
where it adds the docstring to the source code file automatically.
One thing I hoped to talk about at the summit but didn't manage to was doccer (SciPy's internal tool for docstring deduplication). MNE-Python adopted/adapted doccer many years ago, and it helped us find and fix many outdated/inaccurate docstrings.
The problem we're facing is that
Problem 1 alone wouldn't be so bad (arguably an advantage, as it reduces scrolling past screens and screens of docstring between snatches of actual code), but combined with problem 2 it has left some of our devs in a perpetually frustrated state.
My questions are:
?
(likemne.what.ever?
)" but I'm interested in other approaches