Function/class signatures do not work properly when using Py3 style annotations, and type definitions are conditionally imported using typing.TYPE_CHECKING.
Minimal example:
import typing
if typing.TYPE_CHECKING:
from .session import Session
class Test:
def __init__(self, param: 'Session') -> None:
pass
I use autodoc to write documentation about Test class in my index.rst:
.. autoclass:: mytest.test.Test
:members:
This causes the following error
..../classes.rst:4: WARNING: error while formatting arguments for ...test.Test: name 'Session' is not defined
Documentation does not display class initialization signature (nor any other function/method possible signatures) at all.
Documentation displays class and its signatures properly.
What is the current status of this issue? The problem is that with typing you can do special imports, if typing.TYPE_CHECKING and import modules you only need for type checking to avoid circular imports and sphinx is not importing those modules.
Is there an update on this issue? Does anyone have a workaround until a fix is merged? other than removing type hints
As always, big thank you to the maintainers for an incredible tool.
It seems the latest Sphinx (v3.1.2) does not raise any warnings on building document using the reported code. I don't know which release fixed this.
Anyway, this issue was already resolved. Now I'm closing this.
Please file a new issue if you still have the same error.
Most helpful comment
What is the current status of this issue? The problem is that with typing you can do special imports,
if typing.TYPE_CHECKINGand import modules you only need for type checking to avoid circular imports and sphinx is not importing those modules.