-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
WIP, BUG: Implement custom role for numpydoc parameters. #484
base: main
Are you sure you want to change the base?
Conversation
start_idx = m.start() | ||
# If the opening backtick is preceded by a ":" or "`", it's already | ||
# a role or literal markup, respectively, and should not be changed | ||
if start_idx != 0: |
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.
A bit less fragile?
if start_idx != 0: | |
if start_idx > 0: |
This would be a great and something I've wanted for a long time! One idea would be to have a weak dependency on
which I've also wanted and would be nice to have as part of this PR or a follow-up. But as an alternative that I think makes more sense, it looks like the MIT-linensed code for sphinx-params is only ~400 lines, so it wouldn't be too much work to roll our own similar version while fixing/customize some stuff based on our use case:
|
Any progress here? We are getting close to turning on nit-picky mode in NumPy and need this to clean up parameter formatting |
Thanks for the ping @mattip . A quick summary on the current status: I think this approach is generally tenable and will resolve the aforementioned issue generally for many libraries. The big caveat that falls into the "needs decision" category is that adding this feature would break instances of rst tables that incorporate a single-backticked parameter. This is a baked-in limitation due to the fact that numpydoc does an rst->rst->ast conversion rather than an rst->ast conversion directly. This already affects other components in numpydoc, such as references (see also #130), so I don't think this should be a hard blocker, but YMMV. On the TODO-side of things, there are two main things left:
I've done 2) to some extent (testing with numpy and networkx), but I haven't gone through the full exercise including summarizing the results. I'll aim to tackle these things ASAP, but this is very much a in-free-time activity 🙃 . |
I'm somewhat concerned on this approach.
At least this needs very clear documentation and should be configurable. Context: In matplotlib, we're using An alternative and more standard approach would be to try and make |
@rossbar will we be able to link to the description of the return value, too? We didn't specifically mention the return value in the style guide. |
The numpydoc standard states:
In sphinx itself, single-backticks are used to indicate the
default_role
, which ispy:obj
by default. Long story short, this tends to result in a lot of nitpicky link warnings from sphinx due to parameter names. See #419 (comment) for details.This PR aims to resolve this situation by adding a
numpydoc_parameter_role
configuration. The general idea is as follows:When parsing the docstring, numpydoc will find all text enclosed in single backticks and compare it against the function parameters. Any matches will be explicitly converted to use the
numpydoc_param_role
; all others will be left as-is to use the sphinxdefault_role
.TODOs
numpydoc_parameter_role
a sphinx config value (currently hard-coded)Extensions
For now I aim to use the
:emphasis:
role as it's built in to sphinx and will fix the nitpicky warnings. Ultimately I'd like to expand this so that numpydoc parameters become anchor links in the docstring like thesphinx-paramlinks
extension.