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
autodocs does not work well with instance attributes. #904
Comments
From Antonio Valentino on 2012-07-08 15:51:57+00:00 Same problem for me. The following doc {{{ Test 7.. currentmodule:: module .. autoclass:: Foo Attributes.. autoattribute:: Foo.bar .. autoattribute:: Foo.flox .. autoattribute:: Foo.baz .. autoattribute:: Foo.qux .. autoattribute:: Foo.spam Test 8.. currentmodule:: module .. autoclass:: Foo
}}} do not build correctly and gives the following error: {{{ /home/antonio/tmp/sphinx-autoattribute-issue/doc/test_autoattr.rst:86: WARNING: autodoc can't import/find attribute 'module.Foo.qux', it reported error: "qux", please check your spelling and sys.path Build finished. The HTML pages are in _build/html. The python code I'm trying to document is the one used in the sphinx documentation as example (http://sphinx.pocoo.org/ext/autodoc.html?highlight=autoattribute#directive-autoattribute): {{{ class Foo:
}}} |
From Alexander Stepanov on 2012-11-06 10:07:22+00:00 I have same problem :( |
From Jon Waltman on 2012-11-09 06:18:12+00:00 The case where you give an explicit :members: list
Instance attributes are not evaluated and getattr'd like other
The autoattribute directive still doesn't work for instance I'm not sure if this is the intended behavior and |
From Alexander Stepanov on 2012-11-13 12:35:15+00:00 Jonathan Beavers Waltman
So what is a value of printing "None" near each attribute if it is only possible value? It's ugly! |
From Johannes Dewender on 2013-01-24 13:59:07+00:00 There is a |
Just wanted to share a hack on that topic. I managed to avoid displaying values for all attributes with a single piece of code in my
# Hack:
# Replace the `sphinx.ext.autodoc.object_description()` function
# in the `sphinx.ext.autodoc` module.
def no_object_description(obj):
raise ValueError("No value for data/attributes")
import sphinx.ext.autodoc
sphinx.ext.autodoc.object_description = no_object_description Don't know whether there is a simple and safer way to do this? |
About But the second problem that the
|
…utofunction So far, autofunction only checks the existence of the class variable. As a result, it crashes with AttributeError if an instance variable is specified. This adds an exisitence for instance attributes via ModuleAnalyzer before getattr-check.
@tk0miya Thanks for the contribution! I still encounter |
@g6ai Could you file a new issue, please? I'd like to know what is happened on your PC. |
Instance attributes set in an init method can be documented with
#:
comments. When using the autoclass directive with :members: and no list of members, these attributes are picked up by Sphinx, but they are documented with a value of "None", even though there is no such default value.Additionally, if using :members: with an explicit member list or if using the autoattribute directive, the attribute is not documented and Sphinx prints a traceback on the terminal (but continue with the rest of the document). For example:
The text was updated successfully, but these errors were encountered: