-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
autodoc: Allow overloaded functions to have different docstrings #7787
Comments
It sounds good. But it is very difficult to support inheritance, f-string and other features. And I think this is not commonly used. |
I don't see how |
It is great to get overload support! Perhaps I missed it in one of the other issues/PRs but is it correctly understood that only .. function:: my_bytes(n: int)
my_bytes(s: bytes) is supposed to work right now, while .. function:: my_bytes(n: int)
.. function:: my_bytes(s: bytes) yields a duplication error? |
@jakobandersen: I think that .. function:: my_bytes(n: int)
my_bytes(s: bytes) has worked for quite a long time. What changed recently is that I think your problem can be solved with: .. function:: my_bytes(n: int)
:no-index:
.. function:: my_bytes(s: bytes) |
Ah, I see. I suggest to add a note in the Python domain documentation (not sure what the best way to write it is currently). Indeed the |
Agreed, I didn't even know
If you're willing to put in a bit more thinking, how do you think the constructors for my class here should be documented? Right now, I'm just using |
Oh, I don't know that. It means we can get docstrings via AST, great!
|
@eric-wieser, I'm not too familiar with the domain so it's tricky to judge, but to me it looks like 2 or possibly 3 different groups: default and copy constructor, and then the rest, or the rest partitioned in some way. |
Having a better way to handle overloaded functions would be great. Currently trying to make something work.
It would be nice if we could have a description for each overloaded function without duplicating text. |
@eric-wieser , is it here? https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.step.html#torch.optim.Optimizer.step @overload
def step(self, closure: None = ...) -> None:
...
@overload
def step(self, closure: Callable[[], float]) -> float:
...
def step(self, closure: Optional[Callable[[], float]] = None) -> Optional[float]:
r"""Performs a single optimization step (parameter update). |
No, I don't think the original request works yet. The last example posted has a single doc string per overload, instead of a unique doc string for each overload. |
yes please |
If would be great if sphinx could emit all of the docstrings for something like:
As of the fix to #3610, autodoc emits:
but does not extract the first two docstrings.
Perhaps one reasonable option would be to emit
although this doesn't scale to
.. class
particularly well.Another choice would be to render numbers next to the overloads (in the style of cppreference), and then refer to them in the text. In its most minimal form, that would be:
but perhaps new directives or roles could be introduced to render that better:
The text was updated successfully, but these errors were encountered: