diff --git a/python/psi-api/src/com/jetbrains/python/psi/StructuredDocString.java b/python/psi-api/src/com/jetbrains/python/psi/StructuredDocString.java index 9d27c478396b..e32327d4577a 100644 --- a/python/psi-api/src/com/jetbrains/python/psi/StructuredDocString.java +++ b/python/psi-api/src/com/jetbrains/python/psi/StructuredDocString.java @@ -35,11 +35,15 @@ public interface StructuredDocString { String createParameterType(@NotNull String name, @NotNull String type); String getSummary(); - String getDescription(); + String getDescription(); // for formatter List getParameters(); + + /** + * @return all names of parameters mentioned in the docstring as substrings. + */ List getParameterSubstrings(); - + /** * @param paramName {@code null} can be used for unnamed parameters descriptors, e.g. in docstring following class attribute */ @@ -51,47 +55,41 @@ public interface StructuredDocString { */ @Nullable Substring getParamTypeSubstring(@Nullable String paramName); - + /** * @param paramName {@code null} can be used for unnamed parameters descriptors, e.g. in docstring following class attribute */ @Nullable String getParamDescription(@Nullable String paramName); - /** * Keyword arguments are those arguments that usually don't exist in function signature, * but are passed e.g. via {@code **kwargs} mechanism. */ List getKeywordArguments(); List getKeywordArgumentSubstrings(); + // getKeywordArgumentType(name) // getKeywordArgumentTypeString(name) @Nullable String getKeywordArgumentDescription(@Nullable String paramName); - @Nullable String getReturnType(); @Nullable Substring getReturnTypeSubstring(); - @Nullable - String getReturnDescription(); - List getRaisedExceptions(); @Nullable - String getRaisedExceptionDescription(@Nullable String exceptionName); - + String getReturnDescription(); // for formatter + List getRaisedExceptions(); // for formatter + + @Nullable + String getRaisedExceptionDescription(@Nullable String exceptionName); // for formatter + // getAttributes // getAttributeSubstrings // getAttributeType(name) // getAttributeTypeSubstring(name) @Nullable - String getAttributeDescription(); - + String getAttributeDescription(); // for formatter + // Tags related methods - - @Nullable - Substring getParamByNameAndKind(@NotNull String name, String kind); - - @Nullable - Substring getParamNameSubstring(); } diff --git a/python/src/com/jetbrains/python/codeInsight/intentions/SpecifyTypeInDocstringIntention.java b/python/src/com/jetbrains/python/codeInsight/intentions/SpecifyTypeInDocstringIntention.java index b3fc5cc6132e..7b2f12857a93 100644 --- a/python/src/com/jetbrains/python/codeInsight/intentions/SpecifyTypeInDocstringIntention.java +++ b/python/src/com/jetbrains/python/codeInsight/intentions/SpecifyTypeInDocstringIntention.java @@ -29,6 +29,7 @@ import com.jetbrains.python.debugger.PySignatureCacheManager; import com.jetbrains.python.documentation.DocStringUtil; import com.jetbrains.python.documentation.PyDocstringGenerator; import com.jetbrains.python.psi.*; +import com.jetbrains.python.toolbox.Substring; import org.jetbrains.annotations.NotNull; /** @@ -109,7 +110,11 @@ public class SpecifyTypeInDocstringIntention extends TypeIntention { PyFunction pyFunction = PsiTreeUtil.getParentOfType(parameter, PyFunction.class); if (pyFunction != null) { final StructuredDocString structuredDocString = pyFunction.getStructuredDocString(); - return structuredDocString != null && structuredDocString.getParamType(StringUtil.notNullize(parameter.getName())) != null; + if (structuredDocString == null) { + return false; + } + final Substring typeSub = structuredDocString.getParamTypeSubstring(StringUtil.notNullize(parameter.getName())); + return typeSub != null && !typeSub.isEmpty(); } return false; } diff --git a/python/src/com/jetbrains/python/documentation/DocStringLineParser.java b/python/src/com/jetbrains/python/documentation/DocStringLineParser.java index ba99a253dc1e..cfdfcd728f57 100644 --- a/python/src/com/jetbrains/python/documentation/DocStringLineParser.java +++ b/python/src/com/jetbrains/python/documentation/DocStringLineParser.java @@ -59,7 +59,7 @@ public abstract class DocStringLineParser { } public int getLineByOffset(int offset) { - return StringUtil.countNewLines(myDocStringContent.subSequence(0, offset)); + return StringUtil.countNewLines(myDocStringContent.getSuperString().subSequence(0, offset)); } @Nullable diff --git a/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java b/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java index 75454fbca394..faf90326ca7b 100644 --- a/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java +++ b/python/src/com/jetbrains/python/documentation/PyDocstringGenerator.java @@ -353,14 +353,25 @@ public class PyDocstringGenerator { @NotNull private String updateDocString() { final DocStringFormat format = getDocStringFormat(); + DocStringUpdater updater = null; + final String docStringIndent = getDocStringIndentation(); if (format == DocStringFormat.EPYTEXT || format == DocStringFormat.REST) { final String prefix = format == DocStringFormat.EPYTEXT ? "@" : ":"; //noinspection unchecked,ConstantConditions - TagBasedDocStringUpdater updater = new TagBasedDocStringUpdater((TagBasedDocString)getStructuredDocString(), - prefix, getDocStringIndentation()); + updater = new TagBasedDocStringUpdater((TagBasedDocString)getStructuredDocString(), prefix, docStringIndent); + } + else if (format == DocStringFormat.GOOGLE) { + //noinspection ConstantConditions + updater = new GoogleCodeStyleDocStringUpdater((SectionBasedDocString)getStructuredDocString(), docStringIndent); + } + else if (format == DocStringFormat.NUMPY) { + //noinspection ConstantConditions + updater = new NumpyDocStringUpdater((SectionBasedDocString)getStructuredDocString(), docStringIndent); + } + if (updater != null) { for (DocstringParam param : myParams) { if (param.isReturnValue()) { - updater.addReturnValue(param.getType()); + updater.addReturnValue((param.getType())); } else { updater.addParameter(param.getName(), param.getType()); diff --git a/python/src/com/jetbrains/python/documentation/SectionBasedDocString.java b/python/src/com/jetbrains/python/documentation/SectionBasedDocString.java index d12b040ab692..08f8f52455e8 100644 --- a/python/src/com/jetbrains/python/documentation/SectionBasedDocString.java +++ b/python/src/com/jetbrains/python/documentation/SectionBasedDocString.java @@ -345,7 +345,12 @@ public abstract class SectionBasedDocString extends DocStringLineParser implemen @Override public List getParameterSubstrings() { - return null; + return ContainerUtil.mapNotNull(getParameterFields(), new Function() { + @Override + public Substring fun(SectionField field) { + return field.getNameAsSubstring(); + } + }); } @Nullable @@ -542,12 +547,6 @@ public abstract class SectionBasedDocString extends DocStringLineParser implemen return null; } - @Nullable - @Override - public Substring getParamByNameAndKind(@NotNull String name, String kind) { - return null; - } - public static class Section { private final Substring myTitle; private final List myFields; @@ -630,7 +629,7 @@ public abstract class SectionBasedDocString extends DocStringLineParser implemen return myType; } - @NotNull + @NotNull public String getDescription() { return myDescription == null ? "" : stripCommonIndent(myDescription, true); } diff --git a/python/src/com/jetbrains/python/documentation/TagBasedDocString.java b/python/src/com/jetbrains/python/documentation/TagBasedDocString.java index 16581c44516b..09f18c78fffa 100644 --- a/python/src/com/jetbrains/python/documentation/TagBasedDocString.java +++ b/python/src/com/jetbrains/python/documentation/TagBasedDocString.java @@ -130,7 +130,7 @@ public abstract class TagBasedDocString extends DocStringLineParser implements S int argEnd = firstArgLineRange.getEndOffset(); while (lineno + 1 < linesCount) { final Substring nextLine = getLine(lineno + 1).trim(); - if (nextLine.length() == 0 || nextLine.startsWith(tagPrefix)) { + if (nextLine.isEmpty() || nextLine.startsWith(tagPrefix)) { break; } argEnd = nextLine.getTextRange().getEndOffset(); @@ -138,7 +138,7 @@ public abstract class TagBasedDocString extends DocStringLineParser implements S } final Substring argValue = new Substring(argName.getSuperString(), argStart, argEnd); final String tagNameString = tagName.toString(); - if (argName.length() == 0) { + if (argName.isEmpty()) { mySimpleTagValues.put(tagNameString, argValue); } else { @@ -219,15 +219,4 @@ public abstract class TagBasedDocString extends DocStringLineParser implements S results.addAll(getTagArguments(PARAM_TYPE_TAGS)); return results; } - - @Override - @Nullable - public Substring getParamByNameAndKind(@NotNull String name, String kind) { - for (Substring s : getTagArguments(kind)) { - if (name.equals(s.getValue())) { - return s; - } - } - return null; - } } diff --git a/python/src/com/jetbrains/python/documentation/docstrings/DocStringBuilder.java b/python/src/com/jetbrains/python/documentation/docstrings/DocStringBuilder.java index 449d65de97da..b21e4c9aeb7c 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/DocStringBuilder.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/DocStringBuilder.java @@ -25,20 +25,22 @@ import java.util.List; /** * @author Mikhail Golubev */ -public abstract class DocStringBuilder { +public abstract class DocStringBuilder { private final List myLines; + public DocStringBuilder() { myLines = new ArrayList(); } @NotNull - public DocStringBuilder addLine(@NotNull String line) { + public This addLine(@NotNull String line) { myLines.add(line); - return this; + //noinspection unchecked + return (This)this; } @NotNull - public DocStringBuilder addEmptyLine() { + public This addEmptyLine() { return addLine(""); } diff --git a/python/src/com/jetbrains/python/documentation/docstrings/DocStringUpdater.java b/python/src/com/jetbrains/python/documentation/docstrings/DocStringUpdater.java index 5724882d013d..87b00b149bcf 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/DocStringUpdater.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/DocStringUpdater.java @@ -21,6 +21,7 @@ import com.jetbrains.python.documentation.DocStringLineParser; import com.jetbrains.python.psi.PyIndentUtil; import com.jetbrains.python.toolbox.Substring; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -104,13 +105,17 @@ public abstract class DocStringUpdater { protected int findLastNonEmptyLine() { for (int i = myOriginalDocString.getLineCount() - 1; i >= 0; i--) { - if (StringUtil.isEmptyOrSpaces(myOriginalDocString.getLine(i))) { + if (!StringUtil.isEmptyOrSpaces(myOriginalDocString.getLine(i))) { return i; } } return 0; } + public abstract void addParameter(@NotNull String name, @Nullable String type); + + public abstract void addReturnValue(@Nullable String type); + private static class Modification implements Comparable { @NotNull final TextRange range; @NotNull final String text; diff --git a/python/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocStringUpdater.java b/python/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocStringUpdater.java index e1826d93c0e8..9db6b61cb7f6 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocStringUpdater.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocStringUpdater.java @@ -29,7 +29,7 @@ public class GoogleCodeStyleDocStringUpdater extends SectionBasedDocStringUpdate @Override void updateParamDeclarationWithType(@NotNull Substring nameSubstring, @NotNull String type) { - insert(nameSubstring.getEndOffset(), "(" + type + ")"); + insert(nameSubstring.getEndOffset(), " (" + type + ")"); } @Override diff --git a/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringBuilder.java b/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringBuilder.java index 1d2812a445ea..add8007b3bf2 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringBuilder.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringBuilder.java @@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable; /** * @author Mikhail Golubev */ -public abstract class SectionBasedDocStringBuilder extends DocStringBuilder { +public abstract class SectionBasedDocStringBuilder extends DocStringBuilder { protected static final String DEFAULT_SECTION_INDENT = StringUtil.repeatSymbol(' ', 4); protected static final String DEFAULT_CONTINUATION_INDENT = StringUtil.repeatSymbol(' ', 4); diff --git a/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringUpdater.java b/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringUpdater.java index d4f7f559fe06..f42a09a9026c 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringUpdater.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/SectionBasedDocStringUpdater.java @@ -37,14 +37,20 @@ public abstract class SectionBasedDocStringUpdater extends DocStringUpdater() { + @Override + public boolean value(Substring substring) { + return substring.toString().equals(name); + } + }); if (nameSub != null) { updateParamDeclarationWithType(nameSub, type); return; @@ -60,36 +66,6 @@ public abstract class SectionBasedDocStringUpdater extends DocStringUpdater fields = paramSection.getFields(); - if (!fields.isEmpty()) { - final SectionField firstField = fields.get(0); - final String newLine = createReturnLine(type, getSectionIndent(paramSection), getFieldIndent(paramSection, firstField)); - insertBeforeLine(getFieldStartLine(firstField), newLine); - } - else { - final String newLine = createReturnLine(type, getSectionIndent(paramSection), getExpectedFieldIndent()); insertAfterLine(getSectionLastTitleLine(paramSection), newLine); } } @@ -97,6 +73,42 @@ public abstract class SectionBasedDocStringUpdater extends DocStringUpdater fields = returnSection.getFields(); + if (!fields.isEmpty()) { + final SectionField firstField = fields.get(0); + final String newLine = createReturnLine(type, getSectionIndent(returnSection), getFieldIndent(returnSection, firstField)); + insertBeforeLine(getFieldStartLine(firstField), newLine); + } + else { + final String newLine = createReturnLine(type, getSectionIndent(returnSection), getExpectedFieldIndent()); + insertAfterLine(getSectionLastTitleLine(returnSection), newLine); + } + } + else { + final int line = findLastNonEmptyLine(); + final String newSection = createBuilder() + .withSectionIndent(getExpectedFieldIndent()) + .addEmptyLine() .startReturnsSection() .addReturnValue(null, type, "") .buildContent(getExpectedSectionIndent(), true); @@ -131,7 +143,7 @@ public abstract class SectionBasedDocStringUpdater extends DocStringUpdater { private final String myTagPrefix; public TagBasedDocStringBuilder(@NotNull String prefix) { @@ -28,32 +28,32 @@ public class TagBasedDocStringBuilder extends DocStringBuilder { } @NotNull - public DocStringBuilder addParameterDescription(@NotNull String name, @NotNull String description) { + public TagBasedDocStringBuilder addParameterDescription(@NotNull String name, @NotNull String description) { return addLine(String.format("%sparam %s: %s", myTagPrefix, name, description)); } @NotNull - public DocStringBuilder addParameterType(@NotNull String name, @NotNull String type) { + public TagBasedDocStringBuilder addParameterType(@NotNull String name, @NotNull String type) { return addLine(String.format("%stype %s: %s", myTagPrefix, name, type)); } @NotNull - public DocStringBuilder addReturnValueType(@NotNull String type) { + public TagBasedDocStringBuilder addReturnValueType(@NotNull String type) { // named return values are not supported in Sphinx and Epydoc return addLine(String.format("%srtype: %s", myTagPrefix, type)); } - public DocStringBuilder addReturnValueDescription(@NotNull String description) { + public TagBasedDocStringBuilder addReturnValueDescription(@NotNull String description) { return addLine(String.format("%sreturn: %s", myTagPrefix, description)); } @NotNull - public DocStringBuilder addExceptionDescription(@NotNull String type, @NotNull String description) { + public TagBasedDocStringBuilder addExceptionDescription(@NotNull String type, @NotNull String description) { return addLine(String.format("%sraise %s: %s", myTagPrefix, type, description)); } @NotNull - public DocStringBuilder addSummary(@NotNull String summary) { + public TagBasedDocStringBuilder addSummary(@NotNull String summary) { return addLine(summary).addLine(""); } } diff --git a/python/src/com/jetbrains/python/documentation/docstrings/TagBasedDocStringUpdater.java b/python/src/com/jetbrains/python/documentation/docstrings/TagBasedDocStringUpdater.java index 27fe1f066f38..114df8b4547f 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/TagBasedDocStringUpdater.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/TagBasedDocStringUpdater.java @@ -41,6 +41,7 @@ public class TagBasedDocStringUpdater extends DocSt protected void scheduleUpdates() { } + @Override public final void addParameter(@NotNull String name, @Nullable String type) { if (type != null) { insertTagLine(createBuilder().addParameterType(name, type)); @@ -50,6 +51,7 @@ public class TagBasedDocStringUpdater extends DocSt } } + @Override public final void addReturnValue(@Nullable String type) { if (type != null) { insertTagLine(createBuilder().addReturnValueType(type)); diff --git a/python/testData/intentions/afterParamTypeInEmptyGoogleDocString.py b/python/testData/intentions/afterParamTypeInEmptyGoogleDocString.py new file mode 100644 index 000000000000..1a2ff39c6415 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInEmptyGoogleDocString.py @@ -0,0 +1,6 @@ +def f(x, y): + """ + + Parameters: + x (object): + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInEmptyNumpyDocString.py b/python/testData/intentions/afterParamTypeInEmptyNumpyDocString.py new file mode 100644 index 000000000000..6c81e1cfb923 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInEmptyNumpyDocString.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + + Parameters + ---------- + x : object + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringEmptyParamSection.py b/python/testData/intentions/afterParamTypeInGoogleDocStringEmptyParamSection.py new file mode 100644 index 000000000000..ae8aafb7abbd --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringEmptyParamSection.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + x (object): + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringOnlySummary.py b/python/testData/intentions/afterParamTypeInGoogleDocStringOnlySummary.py new file mode 100644 index 000000000000..703367820e13 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringOnlySummary.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + x (object): + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringOnlySummaryOneLine.py b/python/testData/intentions/afterParamTypeInGoogleDocStringOnlySummaryOneLine.py new file mode 100644 index 000000000000..d86dde16a772 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringOnlySummaryOneLine.py @@ -0,0 +1,6 @@ +def f(x, y): + """Summary. + + Parameters: + x (object): + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringOtherParamDeclared.py b/python/testData/intentions/afterParamTypeInGoogleDocStringOtherParamDeclared.py new file mode 100644 index 000000000000..9c4f88fef330 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringOtherParamDeclared.py @@ -0,0 +1,8 @@ +def f(x, y): + """ + Summary. + + Parameters: + x (object): + y: foo + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringOtherSectionExists.py b/python/testData/intentions/afterParamTypeInGoogleDocStringOtherSectionExists.py new file mode 100644 index 000000000000..03d7b519dcbd --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringOtherSectionExists.py @@ -0,0 +1,10 @@ +def f(x, y): + """ + Summary. + + Returns: + Something + + Parameters: + x (object): + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis.py b/python/testData/intentions/afterParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis.py new file mode 100644 index 000000000000..72d85497989e --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + x (object): foo + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInGoogleDocStringParamDeclaredNoParenthesis.py b/python/testData/intentions/afterParamTypeInGoogleDocStringParamDeclaredNoParenthesis.py new file mode 100644 index 000000000000..49be92f2eefd --- /dev/null +++ b/python/testData/intentions/afterParamTypeInGoogleDocStringParamDeclaredNoParenthesis.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + x (object) : foo + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringEmptyParamSection.py b/python/testData/intentions/afterParamTypeInNumpyDocStringEmptyParamSection.py new file mode 100644 index 000000000000..880d2c004353 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringEmptyParamSection.py @@ -0,0 +1,8 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x : object + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringOnlySummary.py b/python/testData/intentions/afterParamTypeInNumpyDocStringOnlySummary.py new file mode 100644 index 000000000000..a8bd222fe9f5 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringOnlySummary.py @@ -0,0 +1,8 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x : object + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringOnlySummaryOneLine.py b/python/testData/intentions/afterParamTypeInNumpyDocStringOnlySummaryOneLine.py new file mode 100644 index 000000000000..38c73b533e2f --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringOnlySummaryOneLine.py @@ -0,0 +1,7 @@ +def f(x, y): + """Summary. + + Parameters + ---------- + x : object + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringOtherParamDeclared.py b/python/testData/intentions/afterParamTypeInNumpyDocStringOtherParamDeclared.py new file mode 100644 index 000000000000..d1322845fb08 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringOtherParamDeclared.py @@ -0,0 +1,10 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x : object + y + foo + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringOtherSectionExists.py b/python/testData/intentions/afterParamTypeInNumpyDocStringOtherSectionExists.py new file mode 100644 index 000000000000..a96b0317ed5c --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringOtherSectionExists.py @@ -0,0 +1,12 @@ +def f(x, y): + """ + Summary. + + Returns + ------- + Something + + Parameters + ---------- + x : object + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringParamDeclaredColon.py b/python/testData/intentions/afterParamTypeInNumpyDocStringParamDeclaredColon.py new file mode 100644 index 000000000000..6513353c3ba2 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringParamDeclaredColon.py @@ -0,0 +1,9 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x : object + foo + """ \ No newline at end of file diff --git a/python/testData/intentions/afterParamTypeInNumpyDocStringParamDeclaredNoColon.py b/python/testData/intentions/afterParamTypeInNumpyDocStringParamDeclaredNoColon.py new file mode 100644 index 000000000000..6513353c3ba2 --- /dev/null +++ b/python/testData/intentions/afterParamTypeInNumpyDocStringParamDeclaredNoColon.py @@ -0,0 +1,9 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x : object + foo + """ \ No newline at end of file diff --git a/python/testData/intentions/afterReturnTypeInEmptyGoogleDocString.py b/python/testData/intentions/afterReturnTypeInEmptyGoogleDocString.py new file mode 100644 index 000000000000..9a531aef416a --- /dev/null +++ b/python/testData/intentions/afterReturnTypeInEmptyGoogleDocString.py @@ -0,0 +1,6 @@ +def f(x, y): + """ + + Returns: + object: + """ \ No newline at end of file diff --git a/python/testData/intentions/afterReturnTypeInEmptyNumpyDocString.py b/python/testData/intentions/afterReturnTypeInEmptyNumpyDocString.py new file mode 100644 index 000000000000..5ea8a8f83566 --- /dev/null +++ b/python/testData/intentions/afterReturnTypeInEmptyNumpyDocString.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + + Returns + ------- + object + """ \ No newline at end of file diff --git a/python/testData/intentions/afterReturnTypeInGoogleDocStringEmptyReturnSection.py b/python/testData/intentions/afterReturnTypeInGoogleDocStringEmptyReturnSection.py new file mode 100644 index 000000000000..e5a8056258f9 --- /dev/null +++ b/python/testData/intentions/afterReturnTypeInGoogleDocStringEmptyReturnSection.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Returns: + object: + """ \ No newline at end of file diff --git a/python/testData/intentions/afterReturnTypeInNumpyDocStringEmptyReturnSection.py b/python/testData/intentions/afterReturnTypeInNumpyDocStringEmptyReturnSection.py new file mode 100644 index 000000000000..36f5b73d17e2 --- /dev/null +++ b/python/testData/intentions/afterReturnTypeInNumpyDocStringEmptyReturnSection.py @@ -0,0 +1,8 @@ +def f(x, y): + """ + Summary. + + Returns + ------- + object + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInEmptyGoogleDocString.py b/python/testData/intentions/beforeParamTypeInEmptyGoogleDocString.py new file mode 100644 index 000000000000..0bd32eef9861 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInEmptyGoogleDocString.py @@ -0,0 +1,2 @@ +def f(x, y): + """""" \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInEmptyNumpyDocString.py b/python/testData/intentions/beforeParamTypeInEmptyNumpyDocString.py new file mode 100644 index 000000000000..0bd32eef9861 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInEmptyNumpyDocString.py @@ -0,0 +1,2 @@ +def f(x, y): + """""" \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringEmptyParamSection.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringEmptyParamSection.py new file mode 100644 index 000000000000..65951d1173d0 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringEmptyParamSection.py @@ -0,0 +1,6 @@ +def f(x, y): + """ + Summary. + + Parameters: + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringOnlySummary.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringOnlySummary.py new file mode 100644 index 000000000000..1104fac7a518 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringOnlySummary.py @@ -0,0 +1,4 @@ +def f(x, y): + """ + Summary. + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringOnlySummaryOneLine.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringOnlySummaryOneLine.py new file mode 100644 index 000000000000..c77483fcf503 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringOnlySummaryOneLine.py @@ -0,0 +1,2 @@ +def f(x, y): + """Summary.""" \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringOtherParamDeclared.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringOtherParamDeclared.py new file mode 100644 index 000000000000..f169092ac65a --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringOtherParamDeclared.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + y: foo + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringOtherSectionExists.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringOtherSectionExists.py new file mode 100644 index 000000000000..9ccd7731295c --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringOtherSectionExists.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Returns: + Something + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis.py new file mode 100644 index 000000000000..c8399756e3fc --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + x (): foo + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInGoogleDocStringParamDeclaredNoParenthesis.py b/python/testData/intentions/beforeParamTypeInGoogleDocStringParamDeclaredNoParenthesis.py new file mode 100644 index 000000000000..0aeec6c463a2 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInGoogleDocStringParamDeclaredNoParenthesis.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters: + x : foo + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringEmptyParamSection.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringEmptyParamSection.py new file mode 100644 index 000000000000..4f12f86dafc9 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringEmptyParamSection.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringOnlySummary.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringOnlySummary.py new file mode 100644 index 000000000000..1104fac7a518 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringOnlySummary.py @@ -0,0 +1,4 @@ +def f(x, y): + """ + Summary. + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringOnlySummaryOneLine.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringOnlySummaryOneLine.py new file mode 100644 index 000000000000..c77483fcf503 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringOnlySummaryOneLine.py @@ -0,0 +1,2 @@ +def f(x, y): + """Summary.""" \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringOtherParamDeclared.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringOtherParamDeclared.py new file mode 100644 index 000000000000..daaa9947a875 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringOtherParamDeclared.py @@ -0,0 +1,9 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + y + foo + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringOtherSectionExists.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringOtherSectionExists.py new file mode 100644 index 000000000000..a2720fba9136 --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringOtherSectionExists.py @@ -0,0 +1,8 @@ +def f(x, y): + """ + Summary. + + Returns + ------- + Something + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringParamDeclaredColon.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringParamDeclaredColon.py new file mode 100644 index 000000000000..2d3e5f73ffcf --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringParamDeclaredColon.py @@ -0,0 +1,9 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x : + foo + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeParamTypeInNumpyDocStringParamDeclaredNoColon.py b/python/testData/intentions/beforeParamTypeInNumpyDocStringParamDeclaredNoColon.py new file mode 100644 index 000000000000..aa12866d605b --- /dev/null +++ b/python/testData/intentions/beforeParamTypeInNumpyDocStringParamDeclaredNoColon.py @@ -0,0 +1,9 @@ +def f(x, y): + """ + Summary. + + Parameters + ---------- + x + foo + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeReturnTypeInEmptyGoogleDocString.py b/python/testData/intentions/beforeReturnTypeInEmptyGoogleDocString.py new file mode 100644 index 000000000000..009fdec68ecd --- /dev/null +++ b/python/testData/intentions/beforeReturnTypeInEmptyGoogleDocString.py @@ -0,0 +1,2 @@ +def f(x, y): + """""" \ No newline at end of file diff --git a/python/testData/intentions/beforeReturnTypeInEmptyNumpyDocString.py b/python/testData/intentions/beforeReturnTypeInEmptyNumpyDocString.py new file mode 100644 index 000000000000..009fdec68ecd --- /dev/null +++ b/python/testData/intentions/beforeReturnTypeInEmptyNumpyDocString.py @@ -0,0 +1,2 @@ +def f(x, y): + """""" \ No newline at end of file diff --git a/python/testData/intentions/beforeReturnTypeInGoogleDocStringEmptyReturnSection.py b/python/testData/intentions/beforeReturnTypeInGoogleDocStringEmptyReturnSection.py new file mode 100644 index 000000000000..16ea28e6d8a1 --- /dev/null +++ b/python/testData/intentions/beforeReturnTypeInGoogleDocStringEmptyReturnSection.py @@ -0,0 +1,6 @@ +def f(x, y): + """ + Summary. + + Returns: + """ \ No newline at end of file diff --git a/python/testData/intentions/beforeReturnTypeInNumpyDocStringEmptyReturnSection.py b/python/testData/intentions/beforeReturnTypeInNumpyDocStringEmptyReturnSection.py new file mode 100644 index 000000000000..98f6758cad5f --- /dev/null +++ b/python/testData/intentions/beforeReturnTypeInNumpyDocStringEmptyReturnSection.py @@ -0,0 +1,7 @@ +def f(x, y): + """ + Summary. + + Returns + ------- + """ \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java b/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java index 4e5b69d7c20c..beb203f246fa 100644 --- a/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java +++ b/python/testSrc/com/jetbrains/python/intentions/PyIntentionTest.java @@ -449,6 +449,56 @@ public class PyIntentionTest extends PyTestCase { doDocReferenceTest(DocStringFormat.GOOGLE); } + // PY-9795 + public void testParamTypeInEmptyGoogleDocString() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringOnlySummaryOneLine() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringOnlySummary() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringEmptyParamSection() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringParamDeclaredNoParenthesis() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringParamDeclaredEmptyParenthesis() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringOtherParamDeclared() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testParamTypeInGoogleDocStringOtherSectionExists() { + doDocReferenceTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testReturnTypeInEmptyGoogleDocString() { + doDocReturnTypeTest(DocStringFormat.GOOGLE); + } + + // PY-9795 + public void testReturnTypeInGoogleDocStringEmptyReturnSection() { + doDocReturnTypeTest(DocStringFormat.GOOGLE); + } + // PY-9795 public void testGoogleDocStubWithTypes() { final PyCodeInsightSettings codeInsightSettings = PyCodeInsightSettings.getInstance(); @@ -489,6 +539,56 @@ public class PyIntentionTest extends PyTestCase { public void testParamTypeInNewNumpyDocString() { doDocReferenceTest(DocStringFormat.NUMPY); } + + // PY-4717 + public void testParamTypeInEmptyNumpyDocString() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringOnlySummaryOneLine() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringOnlySummary() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringEmptyParamSection() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringParamDeclaredNoColon() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringParamDeclaredColon() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringOtherParamDeclared() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testParamTypeInNumpyDocStringOtherSectionExists() { + doDocReferenceTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testReturnTypeInEmptyNumpyDocString() { + doDocReturnTypeTest(DocStringFormat.NUMPY); + } + + // PY-4717 + public void testReturnTypeInNumpyDocStringEmptyReturnSection() { + doDocReturnTypeTest(DocStringFormat.NUMPY); + } // PY-7383 public void testYieldFrom() {