-
Notifications
You must be signed in to change notification settings - Fork 2k
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
enable removal of type hints from autodoc #6361
Comments
As you said, 2) breaks compatibility of extensions. So I feel -1 for the option. On the other hand, 1) is better idea. But I think removal is not best way because it loses type information from document. It would be much better if we can convert them into info field list. I believe it is best way to represent anotations in other way. |
Ok. I opened #6374 as an example. It's not a "breaking" change as in hard-break, it's something that we can start warning about now and just fallback on the original behavior.
This is the goal (for me). Complex type hints make it much harder to read, and I document my types using numpydoc style with napolean :) If #6374 does not look ideal for you that is OK (I'm already monkeypatching that in there so I have a solution currently). But I don't have a lot of confidence in my abilities to actually do option (1) correctly...Just putting the PR up in case maybe I didn't explain breaking change well, it's a "soft break" until 4.x. Edit: for clarity. When you say convert them into info field list, how would the types be removed in the end? I don't understand why converting to info field list helps this. |
In my thought, all annotations on signatures are removed after conversion. At present, Sphinx tries to render type annotations as is. But it is hard to read when its parameters are complex (see #5868). As you said, it is better to describe the types in contents area. But I think we should not write them on docstring manually because they are duplicated. It is annoying to me. In my thought, all annotations are converted into contents as info field lists and remove them all from signature. For example, the following python function will be converted as next reST markup.
|
I completely agree. I resurveyed all of the options recently and ultimately decided to just move on with a compromise:
My ultimate plan was to do what you are suggesting, only specifically for Napoleon extension and numpy style. So long term if we have a way to enable this for the As such the hacky PR I proposed is kind of negative progress on that front. I'll close it. I won't be able to make much headway on this for at least a month, but it's definitely something I want to help enable long term :) |
@shimizukawa @svenevs What do you think this setting?
If agreed, I will implement "none" option at first. And will implement "description" option in future. |
This sounds good to me. Please CC me on PRs to test! When description time comes I think |
It seems @shimizukawa also likes it (see reaction). Let's go forward :-) |
…ehints from signature
I just post #6361 for
I don't have good idea to implement |
…ehints from signature
Close #6361: autodoc: Add autodoc_typehints to suppress typehints from signature
The proposed #6353 solution to #6311 presents an interesting opportunity to consistently and conveniently enable autodoc users to remove type hints. This can be achieved in one of two ways
autodoc_remove_type_hints
or something, which globally removes type hints from signatures. And/or"autodoc-process-signature"
event that is the documenter itself.Type hints are great, but currently some of my signatures become very confused in the docs making it hard to understand.
Describe the solution you'd like
If we make the
documenter
available, this becomes quite simple. A breaking change would be to just tack aself
on at the end of the event. I took a look around, but recovering the documenter from the information currently provided to"autodoc-process-signature"
is not easy to do.sphinx/sphinx/ext/autodoc/__init__.py
Lines 406 to 408 in 165897a
Giving the
documenter
(self
) directly gives us a very clean way to remove type hints:Considerations
Adding an additional parameter is a breaking change.
So the implementation should call with 8 and fallback to calling with 7, issuing a warning that 8 are required now (?).
I'm happy to implement this with some discussion. For example, with (1) adding a global option, would it be better to do something like
so that it's only done for specific types? To be honest, I'd be thrilled with just (2) and add documentation showing users how to remove type hints if they want since it's very little code on their part, and trying to autopopulate the proposed **kwargs from #6353 may add a lot of complexity for not very much benefit.
The text was updated successfully, but these errors were encountered: