-
Notifications
You must be signed in to change notification settings - Fork 128
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.typehints integration not working #273
Comments
After some investigation, it appears that the annotations are added to the sphinx-autoapi/autoapi/mappers/python/mapper.py Lines 396 to 399 in 7872ed0
And they should be picked up by But there are not, because Am I reading this correctly? There are a lot of moving parts that come together in the code, so it's difficult to immediately understand the execution flow. |
So I can see two options:
|
Option 1 was my first instinct as well. It seems silly to have to reimplement this behaviour if it exists in Sphinx already. What do you mean by "has the disadvantage that the annotations now show up both in the parameters list and in the function signature."? I'm guessing that you mean that because the template files write out the signature of the function/method to include the signature, that setting |
That's a good point.
Yes, that's what I meant. Essentially, you end up presenting the type information twice when it's only really needed once.
I think you are right but would have to check the implementation. This might be a situation where autoapi could potentially provide an additional option |
On the note of overloads, I am not even sure how they would be typically documented in the doc string. Is there any convention for this? |
Not really because the convention is to document the types in the signature. The only other thing that you could call a convention (at least from what I've seen so this is by no means official) would be the format of pybind docstrings: """Overloaded function.
1. add(arg0: int, arg1: int) -> int
Add two integers together.
2. add(arg0: float, arg1: float) -> float
Add two floating points numbers together.
""" Side note: pybind outputs the signature of the function on the first line (eg https://github.com/pybind/pybind11/blob/0e01c243c7ffae3a2e52f998bacfe82f56aa96d9/tests/test_factory_constructors.py#L91) because it's coming from C++ so the signature can't be inspected by Python. I haven't included that in the above example because we're talking about Python functions with a real signature. |
I think the right thing to do here is to add support for overloads to |
Yes, I agree that the Support for overloads in |
I'm running into the same issue. Typehints do show up in function signature but do not show up in description with autodoc_typehints = 'description' |
I've finally got around to trying to reproduce your problem, and I can't. For me I do see parameter types get included in the docstring when For example the following function will be rendered as the following
What is incorrect when compared to autodoc is that signature types are still displayed. This is fixable. Adding proper overload support to autodoc.typehints isn't as easy as I initially thought. So for now I will emulate the behaviour of autodoc and output types to the signature only when Given that I've had to integrate even more deeply with Sphinx I'm going to consider our integration with |
@AWhetter I'm using napolean (first item in conf.py extensions[]), perhaps that is causing an issue? The compiled RST looks very similar to yours, but I don't get types in the html descriptions. Maybe I'm missing something else? Using autodoc only I get types in signature and description as shown below. python code
resulting autoapi index.rst
|
Hi! I'm running into this issue as well; it seems to be caused by exactly the lines that @samschott cited above. I've added some changes for reproducing the issue based on the In short, I have two classes documented and hinted identically. The second generates (note the missing types!): If I add this line:
after https://github.com/sphinx-doc/sphinx/blob/7ecf6b88aa5ddaed552527d2ef60f1bd35e98ddc/sphinx/ext/autodoc/typehints.py#L58, I get:
Sphinx's internals are pretty magic to me, but the annotations are cleared after |
@brentyi, thanks for providing an example to reproduce this. Looking through what you have posted here and going through my own docs, I can confirm that type hints are indeed added correctly for a single module but get cleared for all others. |
@AWhetter any chance we could re-open this issue? We have a reproducible case above; @daniel3550 also posted an example independently. No rush, but this feature is pretty critical for folks using type hints. 🙂 |
Apologies for taking so long to address this critical issue. This should be fixed in v1.8.1. |
Thanks @AWhetter!! This will be super useful. |
When inspecting the
data
returned byparse_functiondef
I can see that the type hints are correctly picked up by autoapi. However, includingsphinx.ext.autodoc
and specifying aautodoc_typehints
config value of "description" or "none" does not seem to have any effect at all.I'm not sure how exactly the integration with
sphinx.ext.autodoc
works so it's hard to tell what might be going wrong. Do you have any pointers? It might just be an obvious oversight on my side.The text was updated successfully, but these errors were encountered: