summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Darnell <ben@bendarnell.com>2014-01-20 11:54:51 -0500
committerBen Darnell <ben@bendarnell.com>2014-01-20 11:54:51 -0500
commitc92e9a29ad1a3f23505d9b6e73f5a66c4be642d6 (patch)
tree45382a10ed8d5fb607ad0d2335143aef21fb7bdc
parent847718816365e87961a7df84c277ba968347880b (diff)
downloadsphinx-c92e9a29ad1a3f23505d9b6e73f5a66c4be642d6.tar.gz
Fix an exception introduced by b69b59480cba for __init__ with no docstring.
-rw-r--r--sphinx/ext/autodoc.py5
-rw-r--r--tests/test_autodoc.py16
2 files changed, 19 insertions, 2 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index c454641b..d07014fa 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -1085,8 +1085,9 @@ class ClassDocumenter(ModuleLevelDocumenter):
initdocstring = self.get_attr(
self.get_attr(self.object, '__init__', None), '__doc__')
# for new-style classes, no __init__ means default __init__
- if (initdocstring == object.__init__.__doc__ or # for pypy
- initdocstring.strip() == object.__init__.__doc__): #for !pypy
+ if (initdocstring is not None and
+ (initdocstring == object.__init__.__doc__ or # for pypy
+ initdocstring.strip() == object.__init__.__doc__)): #for !pypy
initdocstring = None
if initdocstring:
if content == 'init':
diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py
index 3735a7b6..3a80e7fc 100644
--- a/tests/test_autodoc.py
+++ b/tests/test_autodoc.py
@@ -348,6 +348,22 @@ def test_get_doc():
directive.env.config.autoclass_content = 'both'
assert getdocl('class', F) == ['Class docstring']
+ # class has __init__ method with no docstring
+ class G(object):
+ """Class docstring"""
+ def __init__(self):
+ pass
+
+ # docstring in the __init__ method of base class will not be used
+ for f in (False, True):
+ directive.env.config.autodoc_docstring_signature = f
+ directive.env.config.autoclass_content = 'class'
+ assert getdocl('class', G) == ['Class docstring']
+ directive.env.config.autoclass_content = 'init'
+ assert getdocl('class', G) == ['Class docstring']
+ directive.env.config.autoclass_content = 'both'
+ assert getdocl('class', G) == ['Class docstring']
+
@with_setup(setup_test)
def test_docstring_processing():