Skip to content

Docstring union return types not wrapped in parentheses, causes rendering issues in VS Code #306

@pfischer1687

Description

@pfischer1687

Describe the bug
When using autoDocstring to generate a docstring for a function that returns a union type like str | None, the generated docstring omits parentheses around the return type. This causes a rendering issue in VS Code, where the return type and summary are not properly parsed or displayed. Adding parentheses around the union type (e.g., (str | None)) fixes the issue.

Versions (please complete the following information):

  • autoDocstring Version: 0.6.1
  • Operating System: Windows 10 WSL 2 Ubuntu 20.04 LTS
  • Vscode Version: 1.100.2

Original Code (with line to generate on):

def foo() -> str | None:
    pass

Expected Result:

def foo() -> str | None:
    """_summary_

    Returns:
        (str | None): _description_
    """
    pass

Actual Result:

def foo() -> str | None:
    """_summary_

    Returns:
        str | None: _description_
    """
    pass

Debug log:

[INFO 11:47:02.670] Generating Docstring at line: 339
[INFO 11:47:02.671] Docstring generated:
    """${1:_summary_}

    Returns:
        ${2:str | None}: ${3:_description_}
    """
[INFO 11:47:02.671] Inserting at position: 339 0
[INFO 11:47:02.679] Successfully inserted docstring

Additional context
Without parentheses around return type:
Image
With:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions