@@ -393,28 +393,29 @@ def read_return_section(self, lines: List[str], start_index: int) -> Tuple[Optio
393393 A tuple containing a `Section` (or `None`) and the index at which to continue parsing.
394394 """
395395 text , i = self .read_block (lines , start_index )
396- annotation = self .context ["annotation" ]
397- description = ""
398396
399- # First try to get the annotation and description from the docstring
400- if text :
401- try :
402- type_ , text = text .split (":" , 1 )
403- except ValueError :
404- self .error ("No type in return description" )
405- else :
406- annotation = type_ .lstrip ()
407- description = text .lstrip ()
408-
409- # If there was no annotation in the docstring then move to signature
410- if annotation is empty and self .context ["signature" ]:
411- annotation = self .context ["signature" ].return_annotation
412-
413- # Early exit if there was no annotation in the docstring or the signature
414- if annotation is empty and not text :
397+ # Early exit if there is no text in the return section
398+ if not text :
415399 self .error (f"Empty return section at line { start_index } " )
416400 return None , i
417401
402+ # First try to get the annotation and description from the docstring
403+ try :
404+ type_ , text = text .split (":" , 1 )
405+ except ValueError :
406+ description = text
407+ annotation = self .context ["annotation" ]
408+ # If there was no annotation in the docstring then move to signature
409+ if annotation is empty and self .context ["signature" ]:
410+ annotation = self .context ["signature" ].return_annotation
411+ else :
412+ annotation = type_ .lstrip ()
413+ description = text .lstrip ()
414+
415+ # There was no type in the docstring and no annotation
416+ if annotation is empty :
417+ self .error ("No return type/annotation in docstring/signature" )
418+
418419 return Section (Section .Type .RETURN , AnnotatedObject (annotation , description )), i
419420
420421 def read_examples_section (self , lines : List [str ], start_index : int ) -> Tuple [Optional [Section ], int ]:
0 commit comments