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

string_processing: Better whitespace allocation for an assert statement #3663

Open
st-pasha opened this issue Apr 26, 2023 · 1 comment
Open
Labels
C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. F: strings Related to our handling of strings T: style What do we want Blackened code to look like?

Comments

@st-pasha
Copy link

Describe the style change

Strange indentation of a long assert statement, in --preview (it works correctly in the stable branch).

Examples in the current (preview) Black style

assert (
    result
    == "Lorem ipsum dolor sit amet,\n"
    "consectetur adipiscing elit,\n"
    "sed doeiusmod tempor incididunt\n"
)

Desired style

assert result == (
    "Lorem ipsum dolor sit amet,\n"
    "consectetur adipiscing elit,\n"
    "sed doeiusmod tempor incididunt\n"
)

Additional context

Similar to #3409

@st-pasha st-pasha added the T: style What do we want Blackened code to look like? label Apr 26, 2023
@st-pasha
Copy link
Author

I think a reasonable rule for the assert statement could be something like this:

  • if an assertion has the form

    assert expr1 op expr2
    

    where op is one of ==, !=, is, is not, in, not in; and the subexpression assert expr1 op fits inside a line length, then prefer to keep that subexpression unbroken, and apply line-breaking to expr2 only.

  • if an assertion has the form

    assert expression, explanation
    

    where the subexpression assert expression fits inside a line length, then prefer to keep that subexpression unbroken, and apply line-breaking to explanation only.

@hauntsaninja hauntsaninja added the C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. label Jul 10, 2023
@hauntsaninja hauntsaninja added the F: strings Related to our handling of strings label Sep 3, 2023
@JelleZijlstra JelleZijlstra changed the title Better whitespace allocation for an assert statement string_processing: Better whitespace allocation for an assert statement Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. F: strings Related to our handling of strings T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants