When I'm included docstrings for instance attributes in the __init__ of a class then using autoclass, I always end up with
attr = None
Documentation of attr
due to this line
Is there a use case for documenting the = None. Can it just always be suppressed? There's no way right now to pass a annotation option to autoclass AFAICT.
You can put a monkeypatch in the conf.py of your project that fixes this problem:
from sphinx.ext.autodoc import (
ClassLevelDocumenter, InstanceAttributeDocumenter)
def iad_add_directive_header(self, sig):
ClassLevelDocumenter.add_directive_header(self, sig)
InstanceAttributeDocumenter.add_directive_header = iad_add_directive_header
Currently, instance attributes are handled by the InstanceAttributeDocumenter class which inherits the method add_directive_header from AttributeDocumenter. It seems to me that instance attributes should never have an annotation set (it's always going to be 'None'). Therefore, it would be very easy to just add a method
def add_directive_header(self, sig):
# type: (unicode) -> None
ClassLevelDocumenter.add_directive_header(self, sig)
to InstanceAttributeDocumenter that overrides the parent method. Am I overlooking something? It seems like a fairly trivial change, so if people agree that this is an acceptable solution, I could probably make a pull request.
Am i missing something or this does not seem to work anymore in the latest versions?
Most helpful comment
You can put a monkeypatch in the
conf.pyof your project that fixes this problem:Currently, instance attributes are handled by the
InstanceAttributeDocumenterclass which inherits the methodadd_directive_headerfromAttributeDocumenter. It seems to me that instance attributes should never have an annotation set (it's always going to be 'None'). Therefore, it would be very easy to just add a methodto
InstanceAttributeDocumenterthat overrides the parent method. Am I overlooking something? It seems like a fairly trivial change, so if people agree that this is an acceptable solution, I could probably make a pull request.