-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add annotation links in signature #65
Comments
Hello! Thanks for the detailed feature request and proof-of-concept! It would indeed be nice to add links to corresponding objects in signature annotations. However, and as you can see, it's not trivial as we must be able to do three things on a same signature:
There's no straight-forward solution to this: there's no order that allow the three operations without breaking one. Still, I thought about it and I think it's doable with a more complex Jinja filter: the idea is to write cross-ref spans first, then stash and replace them with unique ids, that get replaced back with the stashed cross-ref after the highlighting process. I'll have time to work on this soon 🙂 |
I was coming here to request this same feature. @property
def some_property(self) -> SomeType:
"""The description of what you're getting."""
... Typically, the type @property
def some_property(self) -> SomeType:
"""The description of what you're getting.
Returns:
What you are getting.
"""
... But now you have two duplicated sentences. If you remove the first, you are getting rid of the "most important part of the docstring". @property
def some_property(self) -> SomeType:
"""Returns: Description of what you are getting."""
... But then To add links to signatures, I tried modifying the Let me know if I can do anything to help you move this forward, although I have very limited knowledge of how this handler works internally. |
We need to have explicit 'Returns:' sections in properties if we want to link to the return type while mkdocstrings/python#65 is open.
* Export types used in app.py * Export more linked types/errors/classes. * Remove custom template. * Address review comments. We need to have explicit 'Returns:' sections in properties if we want to link to the return type while mkdocstrings/python#65 is open. * Improve docs.
This feature is implemented as part of the insiders version of the Python handler, see https://mkdocstrings.github.io/python/usage/configuration/signatures/#signature_crossrefs |
Yup, I saw the fosstodon announcement! Thanks for your work. |
Is your feature request related to a problem? Please describe.
I often write functions/classes/etc which (I hope) are self-describing enough to exist without a docstring, or which have a docstring that doesn't describe all of the parameters. In this case the only place the parameters are shown are in the signature but their annotations do not contain links (when the annotation exists somewhere else in the codebase).
Describe the solution you'd like
It would be nice if there were an option to auto-generate these links similarly to how they are handled in the "Parameters" section created from the docstring. For example in the following signature:
I would like if the generated html contained a link to
other_module.Baz
.Describe alternatives you've considered
Another option could be to create/update the docstring to add parameters based on the signature, similarly to how auto-docstring generators work but in this case leaving the original code untouched. I implemented a quick hack for this in griffe but I think it would require more work to make it a usable feature.
Additional context
I made a proof-of-concept patch (see below) to the function and signature templates to include links in a similar way to the docstring template. If this feature seems useful I could try to complete in a pull request (maybe adding a flag to turn it on/off and applying it to more than just the function template). The current released version makes a signature like:
And with my patch it looks like (the blue text has two correctly generated links):
The text was updated successfully, but these errors were encountered: