-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fill in default values automatically in documentation #1377
Conversation
This does not yet allow us to replace |
Checks are failing, but only due to unrelated problems. |
Do you want to clean up the commit history (and rebase?) before this is reviewed? Also, how should this be reviewed? I'm assuming one should try to build the documentation, as well as check the code in the individual commits? |
I could do a rebase, I don't think there is much to cleanup in the history. But do you want to review #1349 first? This PR is based on the other one. I would recommend going by commit, looking at the built documentation also makes sense. |
It would be nice to get this reviewed and merged, so I can use it in the Nengo SPA documentation. This implies that it would be nice to have #1349 reviewed and merged first. |
@jgosmann could you rebase this to master now that #1349 is merged? Or I can do it if you'd like. From a quick look, it looks good, though I think I'd rather the sphinx extension stuff be put in I'm also not super sure about removing the defaults from the docstrings. The docstrings might still be used in the context of, e.g., |
FYI, Jan is AFK until Sunday. |
Ah thanks for the heads up! I'll do the rebase for now and leave the rest for Jan when he's back. |
7cd1694
to
71d0f88
Compare
That pretty much cancels all the advantages of this PR except for one (“The default value gets documented in the function signature as it is usually done in Python docs.”). |
I thought that was the point of the PR |
It is one of the points, but I listed four other reasons at the top. Some more thoughts: |
Most users will not know to do something like If removing the defaults from the docstrings is a must-have for this PR @jgosmann then I'll look into the docstring modification approach. |
Maybe not a must-have, but I'd find it really nice. If we were to keep the defaults in the docstrings, could we at least move them out of the type definition into the parameter's description text? |
We could, why do you prefer it there out of curiosity? To explain my reasoning for putting it there in the first place, I put it in the type description so that it's always obvious where it is; I find in the NumPy documentation and other places they will say "optional", but it's not always clear where to find the default. Usually I want to know the default when I see the word "optional" so I thought it made sense to be right beside it. Other ways to be consistent didn't feel great to me. E.g., you could have it at the start, but that way overemphasizes the default when most people just want to know what the kwarg does: radius : int, optional
Defaults to 1.0. The representational radius of the ensemble. It just reads weird. "This defaults to x. By the way, this is ..." Putting it at the end is okay: radius : int, optional
The representational radius of the ensemble. Defaults to 1.0. But visually it is often at an inconsistent place because the previous sentence could end anywhere on that line; i.e., it's hard to visually scan this for defaults: radius : int, optional
The representational radius of the ensemble. Defaults to 1.0.
normalize_encoders : bool, optional
Indicates whether the encoders should be
normalized. Defaults to True. If you manage to not let any inconsistent examples slip through, you can enforce that all "Defaults to x" are on a new line, or a new paragraph if you want it to be scannable in the rendered docs: radius : int, optional
The representational radius of the ensemble.
Defaults to 1.0.
normalize_encoders : bool, optional
Indicates whether the encoders should be normalized.
Defaults to True. But the downside of this is that defaults now always take up at least an entire line (possibly two), where putting it in the type field often results in not using a new line for the default. Another reason that I am not a fan of having it in the long-form description is that the description is meant to be read like a normal English sentence. Consistency isn't the norm for English, so you will often get people putting things like this:
And that's impossible to scan. I have to read the whole description every time to find the default. I guess the main underlying question is whether defaults are something that are important enough to be easily scannable. I would argue yes, but if the consensus feels otherwise, then that's fine. |
I agree with your points and there is probably not a perfect answer. The reasons why I dislike the default in the type definition: The field is intended for the data type and only the data type (plus Putting the default into the description is also in line with what the numpydoc docstring guide says. |
Because no one has replied in two weeks: I stated my arguments and I am aware that either option (putting the defaults into the documentation or not) has advantages and disadvantages. I'm willing to go with whatever the majority thinks is best (or as no one else commented so far, what @tbekolay prefers considering my arguments). Maybe it also helps to get an estimate how much the Sphinx documentation is used vs. other forms to access the documentation. I certainly usually use the Sphinx documentation or look up the source code itself (where the default is stated as part of the parameter definition, so I do not require it to be repeated in the doc string). Sometimes I use the doc string in Jupyter Notebook or Vim, but mostly to remind myself of the function signature, not so much to look up default values. But then I am using Nengo quite a bit and know many of the defaults by heart which does not apply to novice users. |
I think I've mellowed a bit on having the defaults in the docstring itself and so am OK with moving forward with this PR since the only strong opinions seem to be from me and Jan. Having the default automatically inserted and always in sync is likely worth the potential confusion for people using |
Friendly reminder as this would be nice to have for Nengo SPA where some documentation related PRs are in queue anyways. |
71d0f88
to
0892ba9
Compare
Moved the sphinx logic to nengo/nengo-sphinx-theme#33, and updated this PR to use that (pending a new |
One question re using Another minor potential downside: Some parameters do not have defaults that are obvious from the signature. For example, a parameter with the empty dict At first I was hesitant about this, but I think I'm ok with it. It is how Numpy/Scipy does it (as far as I can tell), and I've typically been happy with their documentation, both when I access it online and through |
Without having tested it, I believe this would not be the case. I assume
I believe that his is pretty rare in the Nengo code base. I cannot think of any parameters that has an empty dictionary as default. Maybe there are some with an empty list ... |
62b34a3
to
74ec2b9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated for the new nengo-sphinx-theme
release, this looks good to me.
74ec2b9
to
c383012
Compare
Motivation and context:
This PR adds a Sphinx extension that automatically fills in the defaults in the function signatures for parameters. At this point I'm mostly looking for general feedback, there might be some details that would need some discussion and some things that should be done before this PR gets merged (if it gets merged).
The advantages of this approach:
numpydoc
withsphinx.ext.napoleon
as mentioned here which would cut down on an external dependency. Alsosphinx.ext.napoleon
resolves a bug with numfig that I encountered in Nengo SPA.Potential disadvantages:
Interactions with other PRs:
Currently based on #1349, but doesn't really depend on it and could probably easily be rebased onto master.
How has this been tested?
build the documentation and looked and the function signatures
How long should this take to review?
Types of changes:
Checklist:
Still to do:
function
argument ofnengo.Connection
cannot be resolved at the moment.