diff --git a/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocString.java b/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocString.java index 717966a62a64..bf3f38e4e79a 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocString.java +++ b/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocString.java @@ -150,11 +150,9 @@ public class GoogleCodeStyleDocString extends SectionBasedDocString { } if (description != null) { - // parse line with indentation at least one space greater than indentation of the field - final Pair, Integer> pair = parseIndentedBlock(lineNum + 1, getLineIndentSize(lineNum)); + final Pair, Integer> pair = parseFieldContinuation(lineNum, fieldType); final List nestedBlock = pair.getFirst(); if (!nestedBlock.isEmpty()) { - //noinspection ConstantConditions description = description.union(ContainerUtil.getLastItem(nestedBlock)); } description = description.trim(); diff --git a/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/NumpyDocString.java b/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/NumpyDocString.java index b50d4ca192b3..7ad60da3260e 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/NumpyDocString.java +++ b/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/NumpyDocString.java @@ -140,7 +140,7 @@ public class NumpyDocString extends SectionBasedDocString { if (namesPart == null && !isValidType(type.toString())) { return Pair.create(null, lineNum); } - final Pair, Integer> parsedDescription = parseIndentedBlock(lineNum + 1, getLineIndentSize(lineNum)); + final Pair, Integer> parsedDescription = parseFieldContinuation(lineNum, kind); final List descriptionLines = parsedDescription.getFirst(); if (!descriptionLines.isEmpty()) { description = descriptionLines.get(0).union(descriptionLines.get(descriptionLines.size() - 1)); diff --git a/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocString.java b/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocString.java index b2be201afd3a..b664c150421d 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocString.java +++ b/python/python-psi-impl/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocString.java @@ -30,6 +30,8 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.regex.Pattern; +import static com.jetbrains.python.documentation.docstrings.SectionBasedDocString.FieldType.OPTIONAL_TYPE; + /** * Common base class for docstring styles supported by Napoleon Sphinx extension. * @@ -221,6 +223,13 @@ public abstract class SectionBasedDocString extends DocStringLineParser implemen isSectionStart(lineNum); } + @NotNull + protected Pair, Integer> parseFieldContinuation(int lineNum, @NotNull FieldType fieldType) { + int indent = getLineIndentSize(lineNum); + // we don't need additional indentation for Yields and Returns sections + return parseIndentedBlock(lineNum + 1, fieldType == OPTIONAL_TYPE ? indent - 1 : indent); + } + /** * Consumes all lines that are indented more than {@code blockIndent} and don't contain start of a new section. * Trailing empty lines (e.g. due to indentation of closing triple quotes) are omitted in result. diff --git a/python/testData/quickdoc/MultilineReturnSectionGoogle.html b/python/testData/quickdoc/MultilineReturnSectionGoogle.html new file mode 100644 index 000000000000..665ccaa945f1 --- /dev/null +++ b/python/testData/quickdoc/MultilineReturnSectionGoogle.html @@ -0,0 +1,7 @@ +
Unittest placeholder

Returns:

True if successful, False otherwise. + +The return type is optional and may be specified at the beginning of +the Returns section followed by a colon. + +The Returns section may span multiple lines and paragraphs. +Following lines should be indented to match the first line.
\ No newline at end of file diff --git a/python/testData/quickdoc/MultilineReturnSectionGoogle.py b/python/testData/quickdoc/MultilineReturnSectionGoogle.py new file mode 100644 index 000000000000..dae471192a0d --- /dev/null +++ b/python/testData/quickdoc/MultilineReturnSectionGoogle.py @@ -0,0 +1,12 @@ +def foo(): + """ + Returns: + bool: True if successful, False otherwise. + + The return type is optional and may be specified at the beginning of + the Returns section followed by a colon. + + The Returns section may span multiple lines and paragraphs. + Following lines should be indented to match the first line. + """ + pass \ No newline at end of file diff --git a/python/testData/quickdoc/MultilineReturnSectionNumpy.html b/python/testData/quickdoc/MultilineReturnSectionNumpy.html new file mode 100644 index 000000000000..a095d4b2a99d --- /dev/null +++ b/python/testData/quickdoc/MultilineReturnSectionNumpy.html @@ -0,0 +1,7 @@ +
Unittest placeholder

Returns:

True if successful, False otherwise. + +The return type is optional and may be specified at the beginning of +the Returns section followed by a colon. + +The Returns section may span multiple lines and paragraphs. +Following lines should be indented to match the first line.
\ No newline at end of file diff --git a/python/testData/quickdoc/MultilineReturnSectionNumpy.py b/python/testData/quickdoc/MultilineReturnSectionNumpy.py new file mode 100644 index 000000000000..2994c3f9e617 --- /dev/null +++ b/python/testData/quickdoc/MultilineReturnSectionNumpy.py @@ -0,0 +1,14 @@ +def foo(): + """ + Returns + ------- + bool + True if successful, False otherwise. + + The return type is optional and may be specified at the beginning of + the Returns section followed by a colon. + + The Returns section may span multiple lines and paragraphs. + Following lines should be indented to match the first line. + """ + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/PyQuickDocTest.java b/python/testSrc/com/jetbrains/python/PyQuickDocTest.java index 64fa035f7666..ec633632bdc5 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickDocTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickDocTest.java @@ -721,6 +721,16 @@ public class PyQuickDocTest extends LightMarkedTestCase { checkHTMLOnly(); } + // PY-43035 + public void testMultilineReturnSectionGoogle() { + checkHTMLOnly(); + } + + // PY-43035 + public void testMultilineReturnSectionNumpy() { + checkHTMLOnly(); + } + @Override protected String getTestDataPath() { return super.getTestDataPath() + "/quickdoc/";