-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 + Type Hint difficulties #16473
Comments
The upstream issue been open since 2021... 👀 but yeah would be nice to fix it at the source. Renaming files just for Sphinx to work with type hints, with no other benefits seems excessive. |
It dovetails with the larger discussion of astropy/astropy-APEs#85 for how tools build to standards, standards evolve according to tools, and we can benefit from moving to inside this development cycle. 🐦🐦🐦🐦+🪨 = 🧑🍳 |
What is excessive is the amount of wrestling with Sphinx that adding type annotations requires. |
Especially since other projects don't encounter these difficulties. |
That is a not a fair comparison. I doubt all projects are fully annotated. |
Only ones that are typed are needed for this to be an informative comparison. Those that aren't typed aren't comparable to our current situation. I work with (and have written) a number of projects that are. And they don't have this hard-to-diagnose problem. It would be fantastic if there's a simple solution we could implement to make Sphinx happy. Perhaps if we added functionality to automodapi to add custom sections and sorting of top-level namespaces then we wouldn't need to call automodapi on private modules (which sphinx doesn't know are private so ends up building multiple references), which may be /hopefully(?) is the major issue driving our problems. I added this to the top comment. @mhvk and I discussed something about this in another Issue, though I don't recollect where... |
Just focusing on renaming |
Yes, but this is also what we mean by private API, which
This is exactly the constellation of problems astropy/astropy-APEs#85 is aimed at. If changing private API is too scary because it problematically appears to be public and people are using it we have a major problem for future maintainers! Improving and refactoring code is a necessity. Maintaining a public API MUST be separate from private implementation details.
Sure. That would be nice! And a great short / medium term solution. 👍 But not focusing on fixing deeper structural issues for a sec. I do think we should pursue options 1 & 2! If we can get something working, that's good. If we decide to invest in the future with option 3, it'll take a while and we need 1 or 2 in the meantime. |
From a user perspective, we really do not need to show the API for the the private modules - so maybe just refactoring that and only show ones that are actually used (i.e., the ones that contain units) would be good enough? I really do not want to go the renaming route just because some piece of software that we can make PRs too is mistaken otherwise if one starts using classes in typing -- without typing, there is no issue. |
👍
astropy/astropy-APEs#85 highlights other reasons. But I think for this Issue the relevant point is we all agree that private APIs shouldn't be used downstream and, though we want to minimize downstream friction, if they are using private APIs some friction is inevitable. Disagreements on astropy/astropy-APEs#85 stem from whether the fix should be de jure or de facto. Regardless, for this Issue we might be able to fix the RTD / Sphinx problems in our docs by not referencing private modules ourselves! |
@nstarman - getting back to the sphinx problems: would removing modules like I guess the actual modules that would need to be "de-listed" are |
The Problem:
This issue arose in #15852, where it was discovered that adding type hints to files can result in Sphinx erroneously believing the private source of the type hint, rather than where it is actually made public, should be included in the docs. The result is that Sphinx has too many locations for the object and raises a warning that there are multiple references.
These look like
WARNING: more than one target found for cross-reference 'Equivalency': astropy.units.Equivalency, astropy.units.equivalencies.Equivalency
.The currently-adopted way to fix this is to add
:noindex:
to documentation modules in the docs, e.g.docs/units/ref_api.rst
.How do we fix this?
It would be nice if Sphinx itself could fix this. Type hints are irregularly documented (+link generation broken) sphinx-doc/sphinx#9813 might fix the issue. We should check if it is ever resolved by a PR. This would require the least work from us and would allow us to punt other issues to future maintainers. They'll thank us, I'm sure.
We modify automodapi so that we can sort and section according to files / custom specification. Then we need never call automodapi on a private file and confuse Sphinx into thinking it's public. Maybe this will work. I'm not entirely sure. From work on other repos I am sure of option 3. Even if it doesn't work, this could be a nice feature to have!
We fix it ourselves. The issue only arises when we have an
automodapi
(or similar documentation directive) for a private file that is named as if it's a public file, e.g.astropy.units.quantity.py
. Sphinx has no good way to know that this is actually private. Sphinx will preferastropy.units
but this is a user-friendly heuristic only. When the fileastropy.units.quantity.py
is renamed toastropy.units._quantity.py
then this whole issue is resolved as Sphinx will only findastropy.units
to be public. We could fix this issue and avoid all similar issues by adhering to PEP8 standards in file naming.The text was updated successfully, but these errors were encountered: