@@ -380,6 +380,15 @@ def create_class(self, data, options=None, **kwargs):
380380 )
381381 obj .url_root = self .url_root
382382
383+ for child_data in data .get ("children" , []):
384+ for child_obj in self .create_class (
385+ child_data , options = options , ** kwargs
386+ ):
387+ obj .children .append (child_obj )
388+
389+ # Some objects require children to establish their docstring
390+ # or type annotations (eg classes with inheritance),
391+ # so do this after all children have been created.
383392 lines = sphinx .util .docstrings .prepare_docstring (obj .docstring )
384393 if lines and "autodoc-process-docstring" in self .app .events .events :
385394 self .app .emit (
@@ -388,12 +397,6 @@ def create_class(self, data, options=None, **kwargs):
388397 obj .docstring = "\n " .join (lines )
389398 self ._record_typehints (obj )
390399
391- for child_data in data .get ("children" , []):
392- for child_obj in self .create_class (
393- child_data , options = options , ** kwargs
394- ):
395- obj .children .append (child_obj )
396-
397400 # Parser gives children in source order already
398401 if self .app .config .autoapi_member_order == "alphabetical" :
399402 obj .children .sort (key = operator .attrgetter ("name" ))
@@ -405,14 +408,25 @@ def create_class(self, data, options=None, **kwargs):
405408 def _record_typehints (self , obj ):
406409 if isinstance (
407410 obj , (PythonClass , PythonFunction , PythonMethod )
408- ) and not obj .obj . get ( " overloads" ) :
411+ ) and not obj .overloads :
409412 obj_annotations = {}
410- for _ , name , annotation , _ in obj .obj ["args" ]:
413+
414+ include_return_annotation = True
415+ obj_data = obj .obj
416+ if isinstance (obj , PythonClass ):
417+ constructor = obj .constructor
418+ if constructor :
419+ include_return_annotation = False
420+ obj_data = constructor .obj
421+ else :
422+ return
423+
424+ for _ , name , annotation , _ in obj_data ["args" ]:
411425 if name and annotation :
412426 obj_annotations [name ] = annotation
413427
414- return_annotation = obj . obj . get ( "return_annotation" )
415- if return_annotation :
428+ return_annotation = obj_data [ "return_annotation" ]
429+ if include_return_annotation and return_annotation :
416430 obj_annotations ["return" ] = return_annotation
417431
418432 self .app .env .autoapi_annotations [obj .id ] = obj_annotations
0 commit comments