Skip to content

Parameters with a default value lose their type information from docstrings #574

@christianaguilera-foundry

Description

Consider the following function, which features a parameter that has a default value:

def foobar(name, surname='Smith'):
    """
    This is an example.

    :type name: str
    :type surname: str
    :param name: The name of the user.
    :param surname: The surname of the user.
    """

If sphinx-autodoc-typehints is configured with

typehints_defaults = 'comma'
typehints_use_signature = True

, the mere existence of the default value makes the extension disregard the type information that is present in the docstring:

Current behavior: Type information missing

Ideally, if the parameter provides a default value but not a type hint, the type information in the docstring should be used if it is present:

Expected behavior: Correct type information

Important

The issue is reproducible if typehints_defaults is set to 'comma' or 'braces', but not if set to 'braces-after'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions