diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index ba2f8435dbef6..a1def810f2f2a 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -579,6 +579,9 @@ def generate_function_stub( if not isinstance(docstring, str): docstring = None + if docstring: + docstring = self._indent_docstring(docstring) + ctx = FunctionContext( self.module_name, name, @@ -612,11 +615,7 @@ def generate_function_stub( if inferred[0].args and inferred[0].args[0].name == "cls": decorators.append("@classmethod") - output.extend( - self.format_func_def( - inferred, decorators=decorators, docstring=self._indent_docstring(docstring) - ) - ) + output.extend(self.format_func_def(inferred, decorators=decorators, docstring=docstring)) self._fix_iter(ctx, inferred, output) def _indent_docstring(self, docstring: str) -> str: