Repository: sphinx-doc/sphinx

Issue:
Autoclass interaction between content=both and inherit_doscstrings=True
**Describe the bug**
Documenting class in both the class docstring and the `__init__` docstring has some (to me) counter intuitive behavior with respect to missing `__init__` docstrings in subclasses.

Subclasses without any `__init__` method will be documented with both the subclass class-level docstring and the parent `__init__` docstring, i.e. the `__init__` docstring is "inherited" along with the actual `__init__` method.
Subclasses with an `__init__` without docstring will only be documented with the subclass class-level docstring, i.e. not "inheriting" the `__init__` docstring from the parent.

This is not the same behavior as the built in `help` function or ipython's `?` help.
Using `help(ChildA)` shows `__init__` as inherited from `Parent` with the parents docstring.
Using `help(ChildB)` shows `__init__` as defined in the class, nut still with the parent docstring. The `?` in ipython behaves the same.

**To Reproduce**
Steps to reproduce the behavior:
- Download the MWE in the zip-archive below.
- Unzip
 - Build using `sphinx-build . docs` from the unzipped folder.

**Expected behavior**
Both `ChildA` and `ChildB` have `The parent init docstring` in the compiled docs.

**Your project**
[MWE.zip](https://github.com/sphinx-doc/sphinx/files/3372975/MWE.zip)


**Screenshots**
![screenshot](https://user-images.githubusercontent.com/20397548/60888865-f9e68780-a257-11e9-87c5-1b0dd4f5c7b7.png)
![ipython screenshot](https://user-images.githubusercontent.com/20397548/60889523-7fb70280-a259-11e9-9035-08bf275cd7f8.png)



**Environment info**
- OS: MacOS 10.12.6
- Python version: 3.7.1
- Sphinx version: 2.1.2
- Sphinx extensions:  sphinx.ext.autodoc



Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index 883980a71..ceaa588ac 100644
--- a/CHANGES
+++ b/CHANGES
@@ -44,6 +44,8 @@ Bugs fixed
 * #5502: linkcheck: Consider HTTP 503 response as not an error
 * #6439: Make generated download links reproducible
 * #6486: UnboundLocalError is raised if broken extension installed
+* #6567: autodoc: :confval:`autodoc_inherit_docstrings` does not effect to
+  ``__init__()`` and ``__new__()``
 * #6498: autosummary: crashed with wrong autosummary_generate setting
 * #6507: autosummary: crashes without no autosummary_generate setting
 * #6511: LaTeX: autonumbered list can not be customized in LaTeX
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 4273351bf..f429c25be 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1128,8 +1128,9 @@ def get_doc(self, encoding: str = None, ignore: int = 1) -> List[List[str]]:
         # for classes, what the "docstring" is can be controlled via a
         # config value; the default is only the class docstring
         if content in ('both', 'init'):
-            initdocstring = self.get_attr(
-                self.get_attr(self.object, '__init__', None), '__doc__')
+            __init__ = self.get_attr(self.object, '__init__', None)
+            initdocstring = getdoc(__init__, self.get_attr,
+                                   self.env.config.autodoc_inherit_docstrings)
             # for new-style classes, no __init__ means default __init__
             if (initdocstring is not None and
                 (initdocstring == object.__init__.__doc__ or  # for pypy
@@ -1137,8 +1138,9 @@ def get_doc(self, encoding: str = None, ignore: int = 1) -> List[List[str]]:
                 initdocstring = None
             if not initdocstring:
                 # try __new__
-                initdocstring = self.get_attr(
-                    self.get_attr(self.object, '__new__', None), '__doc__')
+                __new__ = self.get_attr(self.object, '__new__', None)
+                initdocstring = getdoc(__new__, self.get_attr,
+                                       self.env.config.autodoc_inherit_docstrings)
                 # for new-style classes, no __new__ means default __new__
                 if (initdocstring is not None and
                     (initdocstring == object.__new__.__doc__ or  # for pypy


Test patch:
diff --git a/tests/roots/test-ext-autodoc/target/autoclass_content.py b/tests/roots/test-ext-autodoc/target/autoclass_content.py
index 8924ab09b..52b98064a 100644
--- a/tests/roots/test-ext-autodoc/target/autoclass_content.py
+++ b/tests/roots/test-ext-autodoc/target/autoclass_content.py
@@ -33,3 +33,15 @@ def __init__(self):
 
     def __new__(cls):
         """__new__ docstring"""
+
+
+class G(C):
+    """A class inherits __init__ without docstring."""
+    def __init__(self):
+        pass
+
+
+class H(E):
+    """A class inherits __new__ without docstring."""
+    def __init__(self):
+        pass
diff --git a/tests/test_ext_autodoc_configs.py b/tests/test_ext_autodoc_configs.py
index bbf3debaa..1a7224b11 100644
--- a/tests/test_ext_autodoc_configs.py
+++ b/tests/test_ext_autodoc_configs.py
@@ -62,6 +62,18 @@ def test_autoclass_content_class(app):
         '   :module: target.autoclass_content',
         '',
         '   A class having both __init__ and __new__',
+        '   ',
+        '',
+        '.. py:class:: G()',
+        '   :module: target.autoclass_content',
+        '',
+        '   A class inherits __init__ without docstring.',
+        '   ',
+        '',
+        '.. py:class:: H()',
+        '   :module: target.autoclass_content',
+        '',
+        '   A class inherits __new__ without docstring.',
         '   '
     ]
 
@@ -110,6 +122,18 @@ def test_autoclass_content_init(app):
         '   :module: target.autoclass_content',
         '',
         '   __init__ docstring',
+        '   ',
+        '',
+        '.. py:class:: G()',
+        '   :module: target.autoclass_content',
+        '',
+        '   __init__ docstring',
+        '   ',
+        '',
+        '.. py:class:: H()',
+        '   :module: target.autoclass_content',
+        '',
+        '   __new__ docstring',
         '   '
     ]
 
@@ -164,6 +188,22 @@ def test_autoclass_content_both(app):
         '   A class having both __init__ and __new__',
         '   ',
         '   __init__ docstring',
+        '   ',
+        '',
+        '.. py:class:: G()',
+        '   :module: target.autoclass_content',
+        '',
+        '   A class inherits __init__ without docstring.',
+        '   ',
+        '   __init__ docstring',
+        '   ',
+        '',
+        '.. py:class:: H()',
+        '   :module: target.autoclass_content',
+        '',
+        '   A class inherits __new__ without docstring.',
+        '   ',
+        '   __new__ docstring',
         '   '
     ]