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

assertion with multi-line string needlessly spans multiple lines #4247

Closed
Aran-Fey opened this issue Feb 22, 2024 · 2 comments · Fixed by #4289
Closed

assertion with multi-line string needlessly spans multiple lines #4247

Aran-Fey opened this issue Feb 22, 2024 · 2 comments · Fixed by #4289
Labels
T: bug Something isn't working

Comments

@Aran-Fey
Copy link

Describe the bug

When an assert statement has a multi-line string, the condition is split across 3 lines for no reason.

To Reproduce

For example, take this code:

assert some_var == expected_result, f"""
expected: {expected_result}
actual: {some_var}"""

And run it with these arguments:

$ black file.py

The resulting output is:

assert (
    some_var == expected_result
), f"""
expected: {expected_result}
actual: {some_var}"""

Expected behavior

The condition should remain as a single line.

Environment

@Aran-Fey Aran-Fey added the T: bug Something isn't working label Feb 22, 2024
@Drachenfels
Copy link

Would not be marginally cleaner to re-format it to:

assert (
    some_var == expected_result,
    f"""expected: {expected_result}
    actual: {some_var}"""
)

@JelleZijlstra
Copy link
Collaborator

Would not be marginally cleaner to re-format it to:

assert (
    some_var == expected_result,
    f"""expected: {expected_result}
    actual: {some_var}"""
)

No, because that would change the meaning of the code (and make the assertion useless).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants