In implementing type hints (#2031) I learned that Sphinx 9+ is only available for Python versions >= 3.12 and older Python versions use Sphinx 8.
The problem is that Sphinx completely reworked how autodoc works, which significantly changes the behavior with respect to type hints.
Since asdf supports Python >=3.10, depending on which Python version you use you will encounter completely different Sphinx behavior.
Right now running the doc generation code with older Python versions fails because sphinx 8 doesn't correctly handle imports gated behind TYPE_CHECKING blocks (among other reasons).
I was originally using the sphinx-autodoc-typehints plugin to resolve these issues but having that plugin enabled in Sphinx 9 causes a whole set of new problems. Additionally, regardless of version it seems to break cross-references for type aliases.
Potential Solutions
- Move the doc generation code into its own unpublished package (in the same repo), set its required Python version to
>=3.12, and sphinx >=9.0. To me this seems like the best solution because it allows us to use the latest Sphinx version and it doesn't impact the main package.
- Update the sphinx config to enable
autodoc_use_legacy_class_based, which forces sphinx 9+ to use the old autodoc implementation. This would ensure parity across Python versions, but it would also break type hints in the ways described above.
- Change nothing, and just add a note for developers that you need to be using Python
>=3.12 in order to build the documentation.
In implementing type hints (#2031) I learned that Sphinx 9+ is only available for Python versions
>= 3.12and older Python versions use Sphinx 8.The problem is that Sphinx completely reworked how autodoc works, which significantly changes the behavior with respect to type hints.
Since
asdfsupports Python>=3.10, depending on which Python version you use you will encounter completely different Sphinx behavior.Right now running the doc generation code with older Python versions fails because sphinx 8 doesn't correctly handle imports gated behind
TYPE_CHECKINGblocks (among other reasons).I was originally using the sphinx-autodoc-typehints plugin to resolve these issues but having that plugin enabled in Sphinx 9 causes a whole set of new problems. Additionally, regardless of version it seems to break cross-references for type aliases.
Potential Solutions
>=3.12, andsphinx >=9.0. To me this seems like the best solution because it allows us to use the latest Sphinx version and it doesn't impact the main package.autodoc_use_legacy_class_based, which forces sphinx 9+ to use the old autodoc implementation. This would ensure parity across Python versions, but it would also break type hints in the ways described above.>=3.12in order to build the documentation.