-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
feature: link to re-export instead of inserting full documentation #167
Comments
Hey, thanks for the feature request! So IMO this has more to do with mkdocstrings-python than Griffe. IMO again, Griffe does the correct thing here: it loads everything it can from your package. And it actually knows that Now, mkdocstrings-python could try to be a bit more clever than it is right now, and guess the intent of the user, which is to render But, what should it do with the other locations? Hide them? Render links? What I mean is that, currently, I believe you are opting in the "render everything recursively" behavior. If you only mean to render docs for objects exposed in the top-level module, you should then inject docs only for the top-module, and not for any submodules. Or if you expose things in submodules, then you should be able to manually exclude (or even automatically exclude with some scripting, as Griffe provides the necessary API) some objects that were already rendered from the top-level module. mkdocstrings-python provides all the necessary options for that too. I'm not saying that what you want is wrong: I actually agree with you and have the same use-case (docs for Griffe render some class twice, in the top-level module page and in submodule pages)! What I'm saying is that it is hard to accomplish what you want in a way that will please everyone, because there is no standard for that. We only have weak conventions (like prefixing names with So, with all this in mind, I think the only solution we can implement is an option in mkdocstrings-python that says "render links to higher locations if they exist". I don't think it will cater to everyone needs, but it's a start. |
Thank for the response. You raise some good points, and let me respond to them :)
That's good to know, and I wasn't aware! I might make a comment there instead.
I think the best option is to render a link. Having used Rust a fair bit, I especially like the idea of a section of re-exports (see links to examples in my original post): Hiding them could be an option, but I don't like it as a default option, especially when the ability to list re-exports is simple, elegant and unobstrusive.
These are good points, and I agree there is no "one size fits all" solution here. Let me do a bit of a brain dump and consider a few scenarios. I'm using the example of a public class, but the same would apply to other documented objects.
Also to address your point that developers have the option to mark their submodules as private, that is perfectly valid. In fact, it may even be beneficial to raise a warning if a class is being repeatedly documented?
I agree, and starting with something is better than nothing. If people can give feedback, then it can also help determine how to take it forward. I would just reverse the option to "render links to lower locations if they exist" (as mentioned above, to both avoid polluting the top modules, and to reflect more closely how the underlying code is structured). |
Awesome feedback, thanks a lot! I agree with the bottom-up approach 🙂 Lets move forward with it (it'll still be optional). Also the idea to warn about objects having multiple public locations is great! I'll implement that too, in |
Let me know if there's anything I can do, whether it be in code contributions, PR reviews, or testing 👍 |
Moving this to mkdocstrings-python 🙂 |
Is your feature request related to a problem? Please describe.
Let's suppose we have a few related classes which are written in separate files, but for convenience are exposed higher up:
with the main
__init__.py
file looking something like:It would appear that Griffe documents each of these classes twice: once where they are defined, and second time for their re-export through
dog/__init__.py
.The duplicated docs are unnecessary and can be a little confusing at first.
Describe the solution you'd like
A way to avoid the duplication and have each class be documented only once.
A nice solution I have seen would be to have a list of re-exports in the same way that the Rust docs do it. See here and here for some examples. Note that the latter example is a common practice in Rust to have a module called
prelude
whose sole purpose is to re-export commonly used types.If it isn't possible for Griffe to detect re-exports, an alternative might be to have some sort of in-file documentation, or perhaps a separate configuration.
Describe alternatives you've considered
The only alternatives I can image are either to:
__all__
in which case the re-export is entirely hidden.Boost priority
The text was updated successfully, but these errors were encountered: