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
Raises: | Exception1 Exception2 – foo |
ExceptionDescriptionRest
def func() -> None
Raises: | Exception1 Exception2 – bar Exception3 Exception4 – foo |