Skip to content

Very awkward line break for assert statements #1483

@miriaford

Description

@miriaford

I'm not sure if this is a bug or feature, but it looks like a bug to me, or at least a super awkward behavior:

To Reproduce

Original lines:

assert my_data_size >= len(my_large_list), 'data size must be at least the length of my large data list'

Black:

assert my_data_size >= len(
    my_large_list
), "data size must be at least the length of my large data list"

Expected behavior

The above formatting does not make any sense to me. It is very awkward and reduces readability considerably. This is the expected formatting:

assert my_data_size >= len(my_large_list), (
    'data size must be at least the length of my large data list'
)

In fact, I can hack the correct behavior by adding a manual break inside the assert error string:

Original file (hack)

assert my_data_size >= len(my_large_list), "data size must be at least" \
                                            " the length of my large data list"

Black:

assert my_data_size >= len(my_large_list), (
    "data size must be at least" " the length of my large data list"
)

Still, if I remove the space between the adjacent strings, Black reverts back to the above behavior. I have lots of assert statements in my code and this becomes a really serious problem.

Environment:

  • Version: 19.10b0
  • OS and Python version: same for Ubuntu and Mac. Python 3.7

Does this bug also happen on master? Yes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linebreakHow should we split up lines?T: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions