docstring_parser icon indicating copy to clipboard operation
docstring_parser copied to clipboard

Parsing of last RST params definition (incorrectly) includes rest-of-docs.

Open thorwhalen opened this issue 11 months ago • 0 comments

Consider this function:

def create_user(username: str, age: int = 20, is_active: bool = True) -> dict:
    """
    Creates a user with the given username, age, and activity status.

    Some more description here.
    Taking several lines.

    :param username: The username of the user.
    :type username: str
    :param age: The age of the user. Defaults to 20.
    :type age: int
    :param is_active: Indicates if the user is active. Defaults to True.
    :type is_active: bool
    :return: A dictionary representing the created user.
    :rtype: dict

    Example:

    >>> create_user("Alice", 25)
    {'username': 'Alice', 'age': 25, 'is_active': True}
    
    """
    return {"username": username, "age": age, "is_active": is_active}

from docstring_parser import parse

t = parse(create_user.__doc__)

The docs are valid RST docs, but are not parsed correctly.

Expected:

assert t.meta[-1].type_name == 'dict'}
assert t.many_returns[-1].type_name   == 'dict'

Actual:

assert t.meta[-1].type_name == 'dict\nExample:\n\n>>> create_user("Alice", 25)\n{\'username\': \'Alice\', \'age\': 25, \'is_active\': True}'
assert t.many_returns[-1].type_name   == 'dict\nExample:\n\n>>> create_user("Alice", 25)\n{\'username\': \'Alice\', \'age\': 25, \'is_active\': True}'

thorwhalen avatar Mar 21 '24 10:03 thorwhalen