From eb36c4030b2a1bab451b081eb3e497e21184bbd2 Mon Sep 17 00:00:00 2001 From: Wesley Banfield Date: Thu, 2 May 2024 11:06:08 +0200 Subject: [PATCH] Add class documentation to class docstrings --- mypy/stubgenc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 57fe2ca03d40..f7849c930925 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -834,7 +834,7 @@ def generate_class_stub(self, class_name: str, cls: type, output: list[str]) -> bases_str = "(%s)" % ", ".join(bases) else: bases_str = "" - if types or static_properties or rw_properties or methods or ro_properties: + if types or static_properties or rw_properties or methods or ro_properties or class_info.docstring: output.append(f"{self._indent}class {class_name}{bases_str}:") for line in types: if ( @@ -845,6 +845,10 @@ def generate_class_stub(self, class_name: str, cls: type, output: list[str]) -> ): output.append("") output.append(line) + if class_info.docstring: + self.indent() + output.append(f'{self._indent}"""{class_info.docstring}"""') + self.dedent() for line in static_properties: output.append(line) for line in rw_properties: