-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Support desc_parameter outside of desc_parameterlist #9692
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
Comments
I'm not sure how to think about this yet. To better understand, can you provide some context to where you need a parameter outside a list? or rather it seems, where you need a list which should not be in parens? There are other places when describing signatures where (comma-separated) lists are needed, with optional start and end markup (e.g., template parameter/argument lists in C++, or nested function parameter lists in both C and C++), where |
@jakobandersen Python implements operators and some other syntax using protocol methods. The goal of the prettyspecialmethods extension (which I linked above) is to render those methods' signatures using the actual syntax they enable rather than as ordinary methods. So for example, you can implement the As for nothing old getting broken, my changes cannot possibly break anything that Sphinx actually supports doing. The behavior is already broken, as I detailed above (even throwing actual exceptions in some cases). The changes are actually more like a fix than they are an addition. I'm only classifying this as a feature request because it's clear that this use case was just plain never anticipated, and the code was written assuming it wouldn't be attempted. The only way these changes could break something is if someone has written code relying on the broken behavior, which is as unsupported as using a bare |
Pretty nice idea.
Note that sphinx/sphinx/domains/python.py Lines 212 to 235 in 063dcfd
_parse_annotation , but instead of putting nodes in a addnodes.desc_parameter then put them in a nodes.emphasis .
|
@jakobandersen As noted in the alternatives I considered, not all translators put emphasis on parameter nodes. It's translator specific. Some also support a In a lot ways, delving into all this validates the point: reproducing I made a deep dive into trying to understand the logic surrounding parameters before I even considered making this request, as I hope the level of detail my responses provide demonstrate. Believe me when I say that providing this upstream change is very likely the simplest way to achieve my end goals. I do not make this proposal lightly. It was only with careful consideration, a very hard look at what was possible and what was not, and a thorough understanding about the impact it would have that I chose to submit this. I believe very strongly that this change will be a significant (even if niche) net positive for Sphinx as a whole, enabling not only my use case, but also simplifying a host of other use cases in the future, without negatively impacting existing users and extensions. Consistent, predictable, and expected (the opposite of surprising) behavior is nearly always a win, even and especially for the developers maintaining the code base. |
Ah, right, there is a bit of more stuff going on in some of them (text, man, and latex at least). I think I got a bit confused in your original post, as even though the Python classes are called "translator" I think I have only seen these components referred to as the "writer"s.
The Line 2112 in a0e986c
So in your case you need to de
Well-written PRs are always welcome.
My best guess is that the writers that short-circuits the child rendering do not supports links anyway (e.g., the text writer).
To my understanding the "only" thing being reused is the code in the methods
Please note that there are often requests for changes to solve specific issues, and I'm merely trying to figure out what the best way forward for Sphinx as a whole is. Your linked changes seems reasonable to me so I suggest making a PR for more detailed review, also by @tk0miya. It would be great if you could expand the documentation of |
@jakobandersen Thank you. Regarding the Regarding the terminology, thanks for the clarification. I was trying to be specific to be more clear, but it backfired.
My apologies if it seemed like I was implying otherwise. I was just trying to make it clear that I am also giving all the due weight to those same concerns, that I am not trying to just ram through something for my own short term benefit at the expense of the project's long term.
Will do. However, I would like to add some tests for the behavior before I take up even more of your time. Can you provide any advice on how to approach adding them? I could well be missing something, but I haven't seen any tests that feed a document tree directly into the writers. I could potentially try to plug into the existing build tests (such as |
Uh oh!
There was an error while loading. Please reload this page.
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 thatdesc_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 adesc_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
desc_parameter
without a parent list is not very useful in Sphinx currently. Examples:desc_parameter
instance 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_parameterlist
and does not appear in__init__
.desc_parameterlist
's child separator will be reused for the separator, since this is only ever set invisit_desc_parameterlist
.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.
desc_parameterlist
node 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_parameterlist
handling, 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_parameter
outside of adesc_parameterlist
is 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_parameter
will grant much greater flexibility to other extension authors and future development work on Sphinx itself than merely modifyingdesc_parameterlist
behavior.emphasis
node. Some translators do not apply emphasis when translatingdesc_parameter
nodes. 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.The text was updated successfully, but these errors were encountered: