37
37
infer_method_arg_types ,
38
38
infer_method_ret_type ,
39
39
)
40
+ from mypy .util import quote_docstring
40
41
41
42
42
43
class ExternalSignatureGenerator (SignatureGenerator ):
@@ -645,8 +646,7 @@ def generate_function_stub(
645
646
if inferred [0 ].args and inferred [0 ].args [0 ].name == "cls" :
646
647
decorators .append ("@classmethod" )
647
648
648
- if docstring :
649
- docstring = self ._indent_docstring (docstring )
649
+ docstring = self ._indent_docstring (ctx .docstring ) if ctx .docstring else None
650
650
output .extend (self .format_func_def (inferred , decorators = decorators , docstring = docstring ))
651
651
self ._fix_iter (ctx , inferred , output )
652
652
@@ -750,9 +750,16 @@ def generate_property_stub(
750
750
)
751
751
else : # regular property
752
752
if readonly :
753
+ docstring = self ._indent_docstring (ctx .docstring ) if ctx .docstring else None
753
754
ro_properties .append (f"{ self ._indent } @property" )
754
755
sig = FunctionSig (name , [ArgSig ("self" )], inferred_type )
755
- ro_properties .append (sig .format_sig (indent = self ._indent ))
756
+ ro_properties .append (
757
+ sig .format_sig (
758
+ indent = self ._indent ,
759
+ docstring = docstring ,
760
+ include_docstrings = self ._include_docstrings ,
761
+ )
762
+ )
756
763
else :
757
764
if inferred_type is None :
758
765
inferred_type = self .add_name ("_typeshed.Incomplete" )
@@ -867,8 +874,16 @@ def generate_class_stub(
867
874
bases_str = "(%s)" % ", " .join (bases )
868
875
else :
869
876
bases_str = ""
870
- if types or static_properties or rw_properties or methods or ro_properties :
877
+
878
+ if class_info .docstring and self ._include_docstrings :
879
+ doc = f" { self ._indent } { quote_docstring (class_info .docstring )} "
880
+ docstring = doc .splitlines (keepends = False )
881
+ else :
882
+ docstring = []
883
+
884
+ if docstring or types or static_properties or rw_properties or methods or ro_properties :
871
885
output .append (f"{ self ._indent } class { class_name } { bases_str } :" )
886
+ output .extend (docstring )
872
887
for line in types :
873
888
if (
874
889
output
@@ -878,14 +893,10 @@ def generate_class_stub(
878
893
):
879
894
output .append ("" )
880
895
output .append (line )
881
- for line in static_properties :
882
- output .append (line )
883
- for line in rw_properties :
884
- output .append (line )
885
- for line in methods :
886
- output .append (line )
887
- for line in ro_properties :
888
- output .append (line )
896
+ output .extend (static_properties )
897
+ output .extend (rw_properties )
898
+ output .extend (methods )
899
+ output .extend (ro_properties )
889
900
else :
890
901
output .append (f"{ self ._indent } class { class_name } { bases_str } : ..." )
891
902
0 commit comments