2626
2727logger = logging .getLogger ('sphinx.ext.autodoc' )
2828
29- _OBJECT_INIT_DOCSTRING = [prepare_docstring (object .__init__ .__doc__ or '' )]
30- _OBJECT_NEW_DOCSTRING = [prepare_docstring (object .__new__ .__doc__ or '' )]
31-
3229
3330def _docstring_lines_for_props (
3431 docstrings : list [list [str ]] | None ,
@@ -146,6 +143,11 @@ def _get_docstring_lines(
146143 parent : Any ,
147144 tab_width : int ,
148145) -> list [list [str ]] | None :
146+ """Decode and return lines of the docstring(s) for the object.
147+
148+ When it returns None, autodoc-process-docstring will not be called for this
149+ object.
150+ """
149151 obj = props ._obj
150152
151153 if props .obj_type in {'class' , 'exception' }:
@@ -198,18 +200,19 @@ def _get_docstring_lines(
198200 return [prepare_docstring (docstring , tab_width ) for docstring in docstrings ]
199201
200202 if props .obj_type == 'method' :
201- docstring = _get_doc (
203+ docstring = getdoc (
202204 obj ,
203- props = props ,
204- inherit_docstrings = inherit_docstrings ,
205- parent = parent ,
206- tab_width = tab_width ,
205+ allow_inherited = inherit_docstrings ,
206+ cls = parent ,
207+ name = props .object_name ,
207208 )
208- if props .name == '__init__' and docstring == _OBJECT_INIT_DOCSTRING :
209- return []
210- if props .name == '__new__' and docstring == _OBJECT_NEW_DOCSTRING :
209+ if (
210+ not docstring
211+ or (props .name == '__init__' and docstring == object .__init__ .__doc__ )
212+ or (props .name == '__new__' and docstring == object .__new__ .__doc__ )
213+ ):
211214 return []
212- return docstring
215+ return [ prepare_docstring ( docstring , tab_width )]
213216
214217 if props .obj_type == 'data' :
215218 # Check the variable has a docstring-comment
@@ -227,13 +230,19 @@ def _get_docstring_lines(
227230
228231 if comment :
229232 return [comment ]
230- return _get_doc (
233+
234+ if obj is UNINITIALIZED_ATTR :
235+ return []
236+
237+ docstring = getdoc (
231238 obj ,
232- props = props ,
233- inherit_docstrings = inherit_docstrings ,
234- parent = parent ,
235- tab_width = tab_width ,
239+ allow_inherited = inherit_docstrings ,
240+ cls = parent ,
241+ name = props .object_name ,
236242 )
243+ if not docstring :
244+ return []
245+ return [prepare_docstring (docstring , tab_width )]
237246
238247 if props .obj_type == 'attribute' :
239248 from sphinx .ext .autodoc .importer import (
@@ -284,49 +293,25 @@ def _get_docstring_lines(
284293 # the wrong thing to display
285294 return None
286295
287- return _get_doc (
296+ docstring = getdoc (
288297 obj ,
289- props = props ,
290- inherit_docstrings = inherit_docstrings ,
291- parent = parent ,
292- tab_width = tab_width ,
298+ allow_inherited = inherit_docstrings ,
299+ cls = parent ,
300+ name = props .object_name ,
293301 )
294-
295- docstring = _get_doc (
296- obj ,
297- props = props ,
298- inherit_docstrings = inherit_docstrings ,
299- parent = parent ,
300- tab_width = tab_width ,
301- )
302- return docstring
303-
304-
305- def _get_doc (
306- obj : Any ,
307- * ,
308- props : _ItemProperties ,
309- inherit_docstrings : bool ,
310- parent : Any ,
311- tab_width : int ,
312- ) -> list [list [str ]] | None :
313- """Decode and return lines of the docstring(s) for the object.
314-
315- When it returns None, autodoc-process-docstring will not be called for this
316- object.
317- """
318- if obj is UNINITIALIZED_ATTR :
319- return []
302+ if not docstring :
303+ return []
304+ return [prepare_docstring (docstring , tab_width )]
320305
321306 docstring = getdoc (
322307 obj ,
323308 allow_inherited = inherit_docstrings ,
324309 cls = parent ,
325310 name = props .object_name ,
326311 )
327- if docstring :
328- return [prepare_docstring ( docstring , tab_width ) ]
329- return []
312+ if not docstring :
313+ return []
314+ return [prepare_docstring ( docstring , tab_width ) ]
330315
331316
332317def _class_variable_comment (props : _ItemProperties ) -> bool :
0 commit comments