-
Notifications
You must be signed in to change notification settings - Fork 71
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
Sphinx-Needs does not work with sphinx-autodoc-typehints
#1370
Comments
It's a tough one, as I'm against including workarounds for other extensions in our code. Is there no way to solve this problem in sphinx-autodoc-typehints? |
I quite understand. It's annoying that this bug is in the interaction between the two extensions, without one of them being clearly 'at fault'.
I don't know to be honest. I could propose to them to not cause doc strings to be parsed twice, but I suspect that would mean having to partly duplicate RSTParser's functionality in sphinx-autodoc-typehints (probably poorly). That seems like a bug-prone approach, and quite heavy on maintenance. How does sphinx-needs hook into |
Heya
Well, it doesn't; it just uses the standard docutils/sphinx infrastructure which already parses the documentation
and this is why this is so problematic; it is basically overriding what sphinx does and will not integrate well with any extension |
Looking into it more, though, I'm not sure if they have good other options. There is no way to construct a docutils-based restructuredtext parser at all without your directives being triggered, as those are stored as global docutils state ( Also, for most extensions this isn't a problem as directives that are not idempotent are rare. |
While running Sphinx-Needs, I ran into the following error:
Sphinx-Needs is correct: the need is parsed twice during the build process:
sphinx-autodoc-typehints
. This extension will convert Python type signatures and 'insert' them into the docstring in the format Sphinx expects. To do so, it needs to figure out where the newly parsed parameters need to go. And to do that, it parses the whole doc string using a freshly instantiated RSTParser.sphinx.ext.autodoc
parses the doc string.One workaround I've found is to use the fact that
sphinx-autodoc-typehints
doesn't specify the file name in its temporary parser. Simply inserting a check for that by replacing directives/need.py line 58 with the following works:I'm unsure whether that is the best way to fix the issue, though.
Thank you for Sphinx-Needs!
The text was updated successfully, but these errors were encountered: