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

Remove newlines in descriptions that span multiple lines #87

Open
bkanuka opened this issue Apr 24, 2024 · 0 comments
Open

Remove newlines in descriptions that span multiple lines #87

bkanuka opened this issue Apr 24, 2024 · 0 comments

Comments

@bkanuka
Copy link

bkanuka commented Apr 24, 2024

I would like to format my docstrings to have a max line length, but these line breaks should not be present after parsing. This is the behaviour of other docstring parsers, as well as markup formats like markdown or rst. A line break should be present if there are 2 newlines.

For example:

from docstring_parser import parse

docstring = """
    short description
    
    Long description that can span multiple lines. This is test sentence 1. This is test sentence 2. I do not want a 
    line break in this sentence.

    Parameters:
        param_1: Description of param_1. This is test sentence 1. This is test sentence 2. This is test sentence 3. I
            do not want a line break in this sentence. 
    """

parsed = parse(docstring)

print("Long description:")
print(repr(parsed.long_description))

print("Parameters:")
for param in parsed.params:
    print(repr(param.description))

gives the output:

Long description:
'Long description that can span multiple lines. This is test sentence 1. This is test sentence 2. I do not want a \nline break in this sentence.'
Parameters:
'Description of param_1. This is test sentence 1. This is test sentence 2. This is test sentence 3. I\ndo not want a line break in this sentence. '

(note that I use repr to make it clear that the newlines are present)

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