Closed johnthagen closed 1 year ago
Immediate workaround: add from __future__ import annotations
at the top of your module.
Explanation: The issue is that we have to support forward references and explicit string annotations:
class A:
def method(self) -> "A": ...
def func() -> "tuple[Any, ...]": ...
...while also supporting string literals:
def func() -> Literal["hello"]: ...
...which is not as easy as it seems.
Adding from __future__ import annotations
at the top helps, because we detect it and then can avoid trying to (re)parse strings in annotations.
In your case, without this import, we try to parse "My name"
, which obviously fails with a syntax error.
Possible solution: instead of failing on the syntax error and logging a warning, we could fallback to just use this part of the annotation as a string.
@pawamoy Thank you for the prompt response and explanation!
Just wanted to confirm that when 53827c8
is released onto PyPI, will this issue be fixed, or will from __future__ import annotations
still be required?
Thanks for asking: no, you won't need from __future__ import annotations
:)
Okay, great. Thanks for the great package!
Wanted to confirm that this issue was fixed after updating to griffe
0.29.1
.
Describe the bug
mkdocstrings-python
/griffe
fails to build documentation if function usesAnnotated[]
type annotation.To Reproduce
Create a Typer application using
Annotated[]
, which is the preferred way to use it:Expected behavior
No warnings or errors generated and documentation builds/renders successfully.
System (please complete the following information):
mkdocstrings-python
version: 1.1.2Additional context