File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ class DocumentableObject(NamedTuple):
4646
4747
4848def clean_docstring (docstring : str ) -> str :
49- return docstring .strip ().replace ("\\ " , "\\ \\ " )
49+ return docstring .rstrip ().replace ("\\ " , "\\ \\ " )
5050
5151
5252def add_docstring_to_libcst_node (
@@ -77,7 +77,23 @@ def add_docstring_to_libcst_node(
7777 return updated_node
7878
7979 indentation = " " * 4 * level
80- indented_docstring = f'"""\n { textwrap .indent (clean_docstring (docstring ), indentation )} \n { indentation } """'
80+
81+ # For a single-line docstring, this can result in funny things like:
82+ #
83+ # ```py
84+ # def foo():
85+ # """A docstring.
86+ # """
87+ # ```
88+ #
89+ # But we don't need to worry about that here: Black sorts that out for us and turns it into:
90+ #
91+ # ```py
92+ # def foo():
93+ # """A docstring."""
94+ # ```
95+ indented_docstring = f'"""{ textwrap .indent (clean_docstring (docstring ), indentation ).lstrip (" " )} \n { indentation } """'
96+
8197 docstring_node = libcst .Expr (libcst .SimpleString (indented_docstring ))
8298
8399 # If the body is just a `...`, replace it with just the docstring.
You can’t perform that action at this time.
0 commit comments