NilsJPWerner / autoDocstring

VSCode extension that generates docstrings for python files
MIT License
676 stars 163 forks source link

[Feature request] Support `Annotated` (Python 3.7+) #293

Open Diogo-Rossi opened 3 weeks ago

Diogo-Rossi commented 3 weeks ago

The Annotated typing is a special type to add context-specific metadata to an annotation.

The doc-string generation could ignore it, as in the docs:

If a library or tool encounters an annotation Annotated[T, x] and has no special logic for the metadata, it should ignore the metadata and simply treat the annotation as T. As such, Annotated can be useful for code that wants to use annotations for purposes outside Python’s static typing system.

A direct use case for this can be, for instance, the Typer library.

Example code

import typer
from typing_extensions import Annotated

def main(name: Annotated[str, typer.Argument()]):
    print(f"Hello {name}")

Expected Result

def main(name: Annotated[str, typer.Argument()]):
    """_summary_

    _extended_summary_

    Args:
        name (str): _description_
    """
    print(f"Hello {name}")

Actual Result

def main(name: Annotated[str, typer.Argument()]):
    """_summary_

    _extended_summary_

    Args:
        name (Annotated[str, typer.Argument): _description_
    """
    print(f"Hello {name}")