Open brian-phasecraft opened 1 year ago
Note that omitting sphinxcontrib.autodoc_pydantic
from conf.py
has the same effect, so this may not be a problem of autodoc-pydantic
.
But removing BaseModel
from the class declaration also allows for documentation to build, so the issue is somewhere in the interplay of sphinx/autodoc/pydantic, so hopefully this is the right place to start.
@brian-phasecraft Thanks for reporting this bug!
I agree with your observation. Given the stack trace, the error originates within sphinx/ext/autodoc/importer.py
. In my opinion, it is not related to autodoc_pydantic
but rather is a result of the interplay between autodoc_mock_imports
, sphinx.ext.autodoc
and pydantic
.
Using autodoc_mock_imports
, you typically want to prevent import errors for packages that are not available during build time. However, in your case, the configuration does not seem to apply.
It would be interesting to see if the same error occurs if you completely remove pydantic from your snippet and instead employ a plain python class.
Hi,
I have noticed that using mock-imported objects as typehints within classes that inherit
BaseModel
causes the documentation to fail to build.For example,
mock_issue.py
with
conf.py
containingresults in HTML files where
MockedImport
is not documented.Secondarily, other files in the same project are also not documented due to this error. Commenting
foo
leads to complete documentation. I am not sure if this is intended / known behaviour, but any fix / workaround would be greatly appreciated.The error is: