sphinx-doc / sphinx-doc/sphinx
Support desc_parameter outside of desc_parameterlist
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
Note: I am actively working on contributing this request. I just need some feedback and maybe a little guidance.
Is your feature request related to a problem? Please describe.
I'm working on improving on sphinxcontrib-prettyspecialmethods, and a roadblock I'm running into is that there's no good way to emulate the formatting generated by desc_parameter. Even if there were, I think that desc_parameter semantically represents what I'm working with (a parameter that ultimately goes to a function) even though I'm trying to represent the function using language syntax rather than the function itself.
Describe the solution you'd like
It seems like the most modest change is to just update the translators to behave sensibly when they encounter a desc_parameter outside of a desc_parameterlist.
I've already begun work doing this. I believe that all that's required is to make the parameter-list based state more consistent by setting it up in __init__ and resetting it on depart and detecting whether the writer is inside a parameter list before trying to write out separators.
Aside from reviewing whether my changes above make sense or if there are other use cases I need to consider, I also need some help identifying where to put tests and maybe what sorts of tests I should write. Since this change is primarily to support manipulating or generating the document tree directly in a way that existing directives don't currently support, it cannot be tested using any existing directives. I wasn't able to locate any tests that work directly with the document tree being fed into a writer or translator. What would be a reasonable way to test these changes? (My intention is to write the tests for failure and then rebase the commits above on top of them.)
Describe alternatives you've considered
- Trying to use a
desc_parameterwithout a parent list is not very useful in Sphinx currently. Examples:- If the
desc_parameterinstance appears before any instance ofdesc_parameterlist, some translators throw an error due to a missing attribute on the translator itself. The attribute is set invisit_desc_parameterlistand does not appear in__init__. - A previous
desc_parameterlist's child separator will be reused for the separator, since this is only ever set invisit_desc_parameterlist. - The writer inserts commas (or whatever the last separator is) both before and after the parameter (at the same time) in some cases, due to the logic depending on counts set in
visit_desc_parameterlist.
Note that these examples indicate that the behavior is somewhat unpredictable or at least surprising, since the output depends on the order of evaluation of nodes within the document tree.
- If the
- I can't use the
desc_parameterlistnode because the parentheses are hard coded in the translators, and I'd like more control over the formatting of the separating symbols than it offers anyway. I suppose strictly speaking, the translator could be modified to give more flexibility todesc_parameterlisthandling, but that seems like it would be a larger change with much wider reaching impact and potential for bugs and breaking other functionality. Given that the behavior for adesc_parameteroutside of adesc_parameterlistis already unsupported, unpredictable, and not particularly useful with the present behavior, it is highly unlikely that anyone is depending on this behavior already, and that means this change is unlikely to break other extensions or customizations. As a bonus, simply enabling a baredesc_parameterwill grant much greater flexibility to other extension authors and future development work on Sphinx itself than merely modifyingdesc_parameterlistbehavior. - I cannot just use an
emphasisnode. Some translators do not apply emphasis when translatingdesc_parameternodes. I wish to emulatedesc_parameter's behavior exactly to ensure future consistency with Sphinx's output, and the best way to do that is to just actually use the class.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the translator init methods and the visit_desc_parameterlist entry point, then trace how desc_parameter nodes are handled outside a parameter list. Add focused document-tree-to-writer tests covering bare parameters, separators, and state reset; done means translators produce predictable output without relying on prior parameter-list state.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100