-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sphinx AutoAPI >=3.2 generates duplicate definitions of class attributes #476
Comments
It should be possible to change AutoAPI to inspect the class docstring and omit the separate documenting of attributes if they're already covered in the class docstring. |
Hmm, I guess the attributes are kind of separately defined in the docstring and the body of the class. I wonder what changed in 3.2 that triggers this now. And I wonder what would happen if I added the types to the docstring. Maybe as a stopgap I'll attach docstrings to the attributes instead of having them in the class docstring. class Timeseries:
"""Multivariate timeseries for anomalies detection and imputation.
Attributes:
xi: Reference to the original values (can be null).
Many methods assume that these represent chronological, regular timeseries.
x: Copy of :attr:`xi` with any flagged values replaced with null.
flags: Flag label for each value, or null if not flagged.
flagged: Running list of flags that have been checked so far.
index: Row index.
columns: Column names.
"""
def __init__(self, x: np.ndarray | pd.DataFrame) -> None:
"""Initialize a multivariate timeseries.
Args:
x: Timeseries with shape (n observations, m variables).
If :class:`pandas.DataFrame`, :attr:`index` and :attr:`columns`
are equal to `x.index` and `x.columns`, respectively.
Otherwise, :attr:`index` and :attr:`columns` are the default
`pandas.RangeIndex`.
"""
self.xi: np.ndarray
self.index: pd.Index
self.columns: pd.Index
if isinstance(x, pd.DataFrame):
self.xi = x.to_numpy()
self.index = x.index
self.columns = x.columns
else:
self.xi = x
self.index = pd.RangeIndex(x.shape[0])
self.columns = pd.RangeIndex(x.shape[1])
self.x: np.ndarray = self.xi.copy()
self.flags: np.ndarray = np.empty(self.x.shape, dtype=object)
self.flagged: list[str] = [] |
AutoAPI used to ignore instance attributes that didn't have a docstring. That was counter to how every other member worked so it was changed in v3.2 such that instance attributes are documented using the normal rules. Instance attributes are a bit of an oddball though because how they're documented varies between tools. What you're aiming for with your |
My stopgap solution of only documenting via docstrings on the attributes themselves seems to work, but documentation of this behavior would be helpful. I was very confused! |
With the update to the
conda-forge
feedstock in #465 I've just upgraded from v3.0.0 to v3.2.1 ofsphinx-autoapi
, and am now getting errors like these when I runsphinx-build
, which I never got before:or
By installing previous versions of
sphinx-autoapi
in my environment usingpip
I see that the problem first appears in v3.2.0. In v3.1.2 the docs build fine.This sounds vaguely like the error that was coming up in #452?
The RST generated by v3.2.1, including the class and its attributes:
vs. by v3.1.2:
So it seems like AutoAPI is generating two versions of the attributes -- one with the
py:
prefix (which includes type information) and one without (which includes the attribute docstrings).The text was updated successfully, but these errors were encountered: