3838 infer_method_arg_types ,
3939 infer_method_ret_type ,
4040)
41+ from mypy .util import quote_docstring
4142
4243
4344class ExternalSignatureGenerator (SignatureGenerator ):
@@ -649,8 +650,7 @@ def generate_function_stub(
649650 if inferred [0 ].args and inferred [0 ].args [0 ].name == "cls" :
650651 decorators .append ("@classmethod" )
651652
652- if docstring :
653- docstring = self ._indent_docstring (docstring )
653+ docstring = self ._indent_docstring (ctx .docstring ) if ctx .docstring else None
654654 output .extend (self .format_func_def (inferred , decorators = decorators , docstring = docstring ))
655655 self ._fix_iter (ctx , inferred , output )
656656
@@ -754,9 +754,14 @@ def generate_property_stub(
754754 )
755755 else : # regular property
756756 if readonly :
757+ docstring = self ._indent_docstring (ctx .docstring ) if ctx .docstring else None
757758 ro_properties .append (f"{ self ._indent } @property" )
758- sig = FunctionSig (name , [ArgSig ("self" )], inferred_type )
759- ro_properties .append (sig .format_sig (indent = self ._indent ))
759+ sig = FunctionSig (name , [ArgSig ("self" )], inferred_type , docstring = docstring )
760+ ro_properties .append (
761+ sig .format_sig (
762+ indent = self ._indent , include_docstrings = self ._include_docstrings
763+ )
764+ )
760765 else :
761766 if inferred_type is None :
762767 inferred_type = self .add_name ("_typeshed.Incomplete" )
@@ -875,8 +880,17 @@ def generate_class_stub(
875880 bases_str = "(%s)" % ", " .join (bases )
876881 else :
877882 bases_str = ""
878- if types or static_properties or rw_properties or methods or ro_properties :
883+
884+ if class_info .docstring and self ._include_docstrings :
885+ doc = quote_docstring (self ._indent_docstring (class_info .docstring ))
886+ doc = f" { self ._indent } { doc } "
887+ docstring = doc .splitlines (keepends = False )
888+ else :
889+ docstring = []
890+
891+ if docstring or types or static_properties or rw_properties or methods or ro_properties :
879892 output .append (f"{ self ._indent } class { class_name } { bases_str } :" )
893+ output .extend (docstring )
880894 for line in types :
881895 if (
882896 output
@@ -886,14 +900,10 @@ def generate_class_stub(
886900 ):
887901 output .append ("" )
888902 output .append (line )
889- for line in static_properties :
890- output .append (line )
891- for line in rw_properties :
892- output .append (line )
893- for line in methods :
894- output .append (line )
895- for line in ro_properties :
896- output .append (line )
903+ output .extend (static_properties )
904+ output .extend (rw_properties )
905+ output .extend (methods )
906+ output .extend (ro_properties )
897907 else :
898908 output .append (f"{ self ._indent } class { class_name } { bases_str } : ..." )
899909
0 commit comments