Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thorwhalen opened this issue Mar 21, 2024 · 0 comments

Comments

@thorwhalen
Copy link

thorwhalen commented Mar 21, 2024

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}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant