diff --git a/python/src/com/jetbrains/python/PyBundle.properties b/python/src/com/jetbrains/python/PyBundle.properties index 30d9b0e623ef..4b36ef7486cc 100644 --- a/python/src/com/jetbrains/python/PyBundle.properties +++ b/python/src/com/jetbrains/python/PyBundle.properties @@ -803,6 +803,7 @@ QDOC.local.sdk.not.found=You need a configured local Python SDK to render docstr QDOC.assigned.to=Assigned to: QDOC.documentation.is.copied.from=Documentation is copied from: QDOC.accessor.kind=Accessor kind: +QDOC.raises=Raises: runcfg.tests.cant_rerun=Can't rerun tests since test IDs can't be resolved. Try to delete run configuration, and create new one using right click. diff --git a/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java b/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java index a2ce15bef6c9..38e3f3970f46 100644 --- a/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java +++ b/python/src/com/jetbrains/python/documentation/PyDocumentationBuilder.java @@ -388,6 +388,17 @@ public class PyDocumentationBuilder { if (returnDescription != null) { mySectionsMap.get(CodeInsightBundle.message("javadoc.returns")).addItem(returnDescription); } + + final String exceptionList = StreamEx.of(structured.getRaisedExceptions()) + .map(name -> { + final String description = structured.getRaisedExceptionDescription(name); + return "

" + name + (StringUtil.isNotEmpty(description) ? " – " + description : "") + "

"; + }) + .joining(); + + if (!exceptionList.isEmpty()) { + mySectionsMap.get(PyBundle.message("QDOC.raises")).addItem(exceptionList); + } } private boolean isAttribute() { diff --git a/python/src/com/jetbrains/python/documentation/docstrings/DocStringUtil.java b/python/src/com/jetbrains/python/documentation/docstrings/DocStringUtil.java index 8046a5c9e623..b7b49b0137eb 100644 --- a/python/src/com/jetbrains/python/documentation/docstrings/DocStringUtil.java +++ b/python/src/com/jetbrains/python/documentation/docstrings/DocStringUtil.java @@ -195,13 +195,17 @@ public class DocStringUtil { } public static boolean isLikeSphinxDocString(@NotNull String text) { - return text.contains(":param ") || - text.contains(":return:") || text.contains(":returns:") || + return text.contains(":param ") || + text.contains(":return:") || text.contains(":returns:") || + text.contains(":raise ") || text.contains(":raises ") || text.contains(":except ") || text.contains(":exception ") || text.contains(":rtype") || text.contains(":type"); } public static boolean isLikeEpydocDocString(@NotNull String text) { - return text.contains("@param ") || text.contains("@return:") || text.contains("@rtype") || text.contains("@type"); + return text.contains("@param ") || + text.contains("@raise ") || text.contains("@raises ") || text.contains("@except ") || text.contains("@exception ") || + text.contains("@return:") || + text.contains("@rtype") || text.contains("@type"); } public static boolean isLikeGoogleDocString(@NotNull String text) { diff --git a/python/testData/quickdoc/ExceptionDescriptionGoogle.html b/python/testData/quickdoc/ExceptionDescriptionGoogle.html new file mode 100644 index 000000000000..9d68d5823dd7 --- /dev/null +++ b/python/testData/quickdoc/ExceptionDescriptionGoogle.html @@ -0,0 +1 @@ +
ExceptionDescriptionGoogle
def func() -> None
Unittest placehoder

Raises:

Exception1

Exception2 – foo

\ No newline at end of file diff --git a/python/testData/quickdoc/ExceptionDescriptionGoogle.py b/python/testData/quickdoc/ExceptionDescriptionGoogle.py new file mode 100644 index 000000000000..8070188f51de --- /dev/null +++ b/python/testData/quickdoc/ExceptionDescriptionGoogle.py @@ -0,0 +1,6 @@ +def func(): + """ + Raises: + Exception1: + Exception2: foo + """ \ No newline at end of file diff --git a/python/testData/quickdoc/ExceptionDescriptionRest.html b/python/testData/quickdoc/ExceptionDescriptionRest.html new file mode 100644 index 000000000000..9c856a4b9e30 --- /dev/null +++ b/python/testData/quickdoc/ExceptionDescriptionRest.html @@ -0,0 +1 @@ +
ExceptionDescriptionRest
def func() -> None
Unittest placehoder

Raises:

Exception1

Exception2 – bar

Exception3

Exception4 – foo

\ No newline at end of file diff --git a/python/testData/quickdoc/ExceptionDescriptionRest.py b/python/testData/quickdoc/ExceptionDescriptionRest.py new file mode 100644 index 000000000000..b094e159cfdf --- /dev/null +++ b/python/testData/quickdoc/ExceptionDescriptionRest.py @@ -0,0 +1,9 @@ +def func(): + """ + + :raises Exception1 + :raise Exception2: bar + :except Exception3: + :exception Exception4: foo + """ + pass diff --git a/python/testSrc/com/jetbrains/python/PyQuickDocTest.java b/python/testSrc/com/jetbrains/python/PyQuickDocTest.java index c01051b8c1f3..68de5fd1f0a4 100644 --- a/python/testSrc/com/jetbrains/python/PyQuickDocTest.java +++ b/python/testSrc/com/jetbrains/python/PyQuickDocTest.java @@ -499,6 +499,14 @@ public class PyQuickDocTest extends LightMarkedTestCase { checkHTMLOnly(); } + public void testExceptionDescriptionRest() { + checkHTMLOnly(); + } + + public void testExceptionDescriptionGoogle() { + checkHTMLOnly(); + } + public void testPackage() { myFixture.copyDirectoryToProject(getTestName(false), ""); final VirtualFile file = myFixture.findFileInTempDir("pkg/__init__.py");