PY-17002 Suggest types inside unclosed parentheses in Google docstrings
authorMikhail Golubev <mikhail.golubev@jetbrains.com>
Fri, 25 Sep 2015 14:04:07 +0000 (17:04 +0300)
committerMikhail Golubev <mikhail.golubev@jetbrains.com>
Mon, 28 Sep 2015 12:30:37 +0000 (15:30 +0300)
python/src/com/jetbrains/python/documentation/docstrings/GoogleCodeStyleDocString.java
python/testData/completion/paramTypeInGoogleDocstringWithoutClosingParenthesis.py [new file with mode: 0644]
python/testData/docstrings/googleNoClosingParenthesisAfterParamType.py [new file with mode: 0644]
python/testSrc/com/jetbrains/python/PySectionBasedDocStringTest.java
python/testSrc/com/jetbrains/python/PythonCompletionTest.java

index 1cb57a177cd0be6f4536a92a25c224688c743324..f2c9b50e01ddfa9d9f8bafc311916ec3c870d769 100644 (file)
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
  */
 public class GoogleCodeStyleDocString extends SectionBasedDocString {
   public static final Pattern SECTION_HEADER = Pattern.compile("^[ \t]*([\\w \t]+):[ \t]*$", Pattern.MULTILINE);
-  private static final Pattern FIELD_NAME_AND_TYPE = Pattern.compile("^[ \t]*(.+?)[ \t]*\\([ \t]*(.*?)[ \t]*\\)[ \t]*$", Pattern.MULTILINE);
+  private static final Pattern FIELD_NAME_AND_TYPE = Pattern.compile("^[ \t]*(.+?)[ \t]*\\([ \t]*(.*?)[ \t]*\\)?[ \t]*$", Pattern.MULTILINE);
 
   public GoogleCodeStyleDocString(@NotNull Substring text) {
     super(text);
diff --git a/python/testData/completion/paramTypeInGoogleDocstringWithoutClosingParenthesis.py b/python/testData/completion/paramTypeInGoogleDocstringWithoutClosingParenthesis.py
new file mode 100644 (file)
index 0000000..721ff95
--- /dev/null
@@ -0,0 +1,5 @@
+def f():
+    """
+    Args:
+        x (str<caret>
+    """
\ No newline at end of file
diff --git a/python/testData/docstrings/googleNoClosingParenthesisAfterParamType.py b/python/testData/docstrings/googleNoClosingParenthesisAfterParamType.py
new file mode 100644 (file)
index 0000000..b3bc965
--- /dev/null
@@ -0,0 +1,6 @@
+def f(x, y):
+    """
+    Args:
+        x (Foo
+        y (Bar : description
+    """
\ No newline at end of file
index 9488be14829e04ad2d83cb7358b963c794d5c06d..166da2926731f52ad7b878d060568884a624de0f 100644 (file)
@@ -378,6 +378,16 @@ public class PySectionBasedDocStringTest extends PyTestCase {
                  "second line", firstExample.getDescription());
   }
 
+  // PY-17002
+  public void testGoogleNoClosingParenthesisAfterParamType() {
+    final GoogleCodeStyleDocString docString = findAndParseGoogleStyleDocString();
+    assertSize(1, docString.getSections());
+    final List<SectionField> params = docString.getSections().get(0).getFields();
+    assertSize(2, params);
+    assertEquals("Foo", params.get(0).getType());
+    assertEquals("Bar", params.get(1).getType());
+  }
+
   @Override
   protected String getTestDataPath() {
     return super.getTestDataPath() + "/docstrings";
index ad48594360a60489e42b8e88c32d5efc411d8c71..4e00465d167aecfd90912455bc2c31e528afce18 100644 (file)
@@ -484,6 +484,18 @@ public class PythonCompletionTest extends PyTestCase {
     });
   }
 
+  // PY-17002
+  public void testParamTypeInGoogleDocstringWithoutClosingParenthesis() {
+    runWithDocStringFormat(DocStringFormat.GOOGLE, new Runnable() {
+      @Override
+      public void run() {
+        final List<String> variants = doTestByFile();
+        assertNotNull(variants);
+        assertSameElements(variants, "str", "basestring");
+      }
+    });
+  }
+
   public void testPep328Completion() {  // PY-3409
     myFixture.copyDirectoryToProject("pep328", "pep328");
     myFixture.configureByFile("pep328/package/subpackage1/moduleX.py");