Closed jklaise closed 5 years ago
What is the offending annotation that fails to render?
I got the same for pandas
:
Exception occurred:
File "/home/audeering.local/hwierstorf/.envs/audata/lib/python3.6/site-packages/sphinx_autodoc_typehints.py", line 60, in get_annotation_args
original = getattr(sys.modules[module], class_name)
KeyError: 'pandas.api.types'
How can I figure out what the offending annotation was exactly?
Edit the sphinx_autodoc_typehints
module and place a try...except
block to catch the KeyError
and add either a print() call that prints the annotation or a debugger breakpoint in there.
Alternatively, if you have an open source project, you can point me to it and I can do that for you.
OK, I changed the beginning of get_annotation_args
to:
def get_annotation_args(annotation, module: str, class_name: str) -> Tuple:
try:
original = getattr(sys.modules[module], class_name)
except KeyError:
print('annotation: {}'.format(annotation))
print('module: {}'.format(module))
print('class_name: {}'.format(class_name))
raise
except AttributeError:
pass
And this returns:
annotation: pandas.api.types.CategoricalDtype
module: pandas.api.types
class_name: CategoricalDtype
For me it worked with version 1.9.0
.
Thanks. It strikes me as odd that the module containing this annotation was not loaded. Can you find the function signature containing this annotation and paste it for me here, along with the associated import?
I'm not completely sure, if this is the correct one, but I have something like this:
from typing import Sequence
import pandas as pd
class Table(HeaderBase):
def __init__(self,
files: Sequence[str],
*,
starts: Sequence[pd.Timedelta] = None,
ends: Sequence[pd.Timedelta] = None)
Note, that in conf.py
I also have something like: autodoc_mock_imports = ['pandas']
And I realized now, that it was also not build completely correct with 1.9.0
:
Removing autodoc_mock_imports
fixes this error and it runs through with 1.10.0
.
The result looks like:
Which is fine, only the Timedelta
entry is not a clickable link.
@jklaise Are you also using autodoc_mock_imports
?
@hagenw Do you have Pandas installed when building the docs, and the Intersphinx inventory loaded for Pandas? If not, there is no way for Sphinx to create the correct link.
@agronholm I am indeed using autodock_mock_imports
, I can debug more tomorrow.
@hagenw Do you have Pandas installed when building the docs, and the Intersphinx inventory loaded for Pandas? If not, there is no way for Sphinx to create the correct link.
Yes, pandas
is installed and intersphinx setup correctly.
I could try to setup a minimal open source project on Wednesday that tries to reproduce the behavior.
Maybe the missing link is related to https://github.com/agronholm/sphinx-autodoc-typehints/issues/47
I could try to setup a minimal open source project on Wednesday that tries to reproduce the behavior.
Yes, that would be very helpful.
I have been wondering if the Sphinx plugins could somehow access the objects inventory without having to load it themselves. That might make it possible to fix #47.
I've just released v1.10.1 which fixes this issue. I also added a regression test to make sure it won't happen again.
Thank you very much for your effort.
If I use autodock_mock_imports
as before now everything runs smoothly and I get the correct links.
If I run without autodock_mock_imports
everything runs smoothly, only the links are missing, as mentioned in https://github.com/agronholm/sphinx-autodoc-typehints/issues/116#issuecomment-549449530
My docs now fail to build with 1.10 (work with 1.9 or lower):
Here's the log file: