Skip to content

Remove newlines in descriptions that span multiple lines #87

Description

@bkanuka

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions