From 8006ae13bc27d117ce6b8fdc8ac91dc8541a670f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Mazzucotelli?= Date: Wed, 12 Jan 2022 14:02:56 +0100 Subject: [PATCH] feat: Support Google raises annotations cross-refs --- src/griffe/docstrings/google.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/griffe/docstrings/google.py b/src/griffe/docstrings/google.py index ba3f00a6..295be21a 100644 --- a/src/griffe/docstrings/google.py +++ b/src/griffe/docstrings/google.py @@ -268,6 +268,10 @@ def _read_raises_section(docstring: Docstring, offset: int) -> tuple[DocstringSe _warn(docstring, line_number, f"Failed to get 'exception: description' pair from '{exception_lines[0]}'") else: description = "\n".join([description.lstrip(), *exception_lines[1:]]).rstrip("\n") + # try to compile the annotation to transform it into an expression + with suppress(AttributeError, SyntaxError): + code = compile(annotation, mode="eval", filename="", flags=PyCF_ONLY_AST, optimize=2) + annotation = code.body and get_annotation(code.body, parent=docstring.parent) # type: ignore[assignment,arg-type] exceptions.append(DocstringRaise(annotation=annotation, description=description)) if exceptions: