Description
Describe the bug
The sphinx autosummary extension turns off the typing.TYPE_CHECKING
flag used by the sphinx-autodoc-typehints extension to do conditional imports of annotation types (among other things), you may want to document this in your README (I just lost a day to searching it out)
To Reproduce
Add "sphinx.ext.autosummary" to the extensions
list (before "sphinx-autodoc-typehints"
) in your docs/conf.py and add a print statement for the typing.TYPE_CHECKING
flag (compare before and after to see that it is switched off)
- If it makes life any easier, I made a minimal reproducible repo to show this here but I'm sure it's trivial to observe this yourself.
- Since this repo is now 'fixed', add "sphinx.ext.autosummary" to the extensions to observe it break (all the library does is print the
typing.TYPE_CHECKING
variable)
- Since this repo is now 'fixed', add "sphinx.ext.autosummary" to the extensions to observe it break (all the library does is print the
Moving it after "sphinx-autodoc-typehints"
reverts the behaviour (the print out goes back to TYPE_CHECKING = True).
Perhaps worth adding a note on this to the README (like you already had for Napoleon), I couldn't figure out what was causing this!
Also to be constructive, do you think it’d be wise to add a test for this? Along the lines of “if the set_check_typing_flag
param was set to True and the TYPE_CHECKING flag does not end up being True, raise an error”?
detected_check_typing_flag = SomehowDetectValueOf("typing.TYPE_CHECKING")
if app.config.set_check_typing_flag and not detected_check_typing_flag:
raise ValueError`
From looking at the code, I’m not sure if there is any such ‘view’ into the process where you’d be able to run such a function SomehowDetectValueOf
, any suggestion/thoughts?
- The
typing.TYPE_CHECKING
is just a module-level constant - I suspect it'd perhaps be possible to check after the app runs if
typing.TYPE_CHECKING
has a different value