Skip to content

Indent of redbaron docstrings leaves trailing white spaces #224

@JohannesBuchner

Description

@JohannesBuchner

Adding a docstring adds indent, including on empty lines.

I am analysing and altering example.py:

def indicator(r, threshold=42):
    if r > threshold:
        return False
    else:
        return True

with the following code

import redbaron
rb = redbaron.RedBaron(open('gendocstr/example2.py').read())
docstring = """Hello world

how is it going?
"""
rb[0].value.insert(0, '"""%s"""' % docstring)
print(rb.dumps())

gives:

def indicator(r, threshold=42):
    """Hello world
    
    how is it going?
    """
    if r > threshold:
        return False
    else:
        return True

The line in the middle is also indented.

This causes linters to complain about trailing newlines.

As far as I can see, there is no way to control the automatic indentation.

This is with redbaron 0.9.2

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