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

black breaks long statement within [] and not around and #1974

Closed
bbkane opened this issue Feb 7, 2021 · 1 comment
Closed

black breaks long statement within [] and not around and #1974

bbkane opened this issue Feb 7, 2021 · 1 comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?

Comments

@bbkane
Copy link

bbkane commented Feb 7, 2021

Describe the bug A clear and concise description of what the bug is.

black replaces:

            is_standard_front_matter = (lines[0] == lines[3] == "---\n") and lines[1] == "layout: default\n"

with

            is_standard_front_matter = (lines[0] == lines[3] == "---\n") and lines[
                1
            ] == "layout: default\n"

It's subjective (and apologies if this should be a style issue, not a bug), but because the and has lower precedence than the conditionals around it, I would find it easier to read if black created teh newline around the and:

            is_standard_front_matter = (lines[0] == lines[3] == "---\n") \
                and lines[1] == "layout: default\n"

This does require a backslash, so reasonable people could disagree :) . I skimmed black's style guide, but didn't see a case representing this. Please close this issue if I'm mistaken about this as a bug.

To Reproduce Steps to reproduce the behavior:

  1. Take this file '...'
lines = [
    "---\n",
    "layout: default\n",
    "title: my title\n",
    "---\n",
]


def need_indent():
    def need_more_indent():
        def even_more_indent():
            is_standard_front_matter = (lines[0] == lines[3] == "---\n") and lines[1] == "layout: default\n"
  1. Run Black on it with these arguments '....'
$ cat tmp.py| black -
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

lines = [
    "---\n",
    "layout: default\n",
    "title: my title\n",
    "---\n",
]


def need_indent():
    def need_more_indent():
        def even_more_indent():
            is_standard_front_matter = (lines[0] == lines[3] == "---\n") and lines[
                1
            ] == "layout: default\n"
reformatted -
All done! ✨ 🍰 ✨
1 file reformatted.
  1. See error
            is_standard_front_matter = (lines[0] == lines[3] == "---\n") and lines[
                1
            ] == "layout: default\n"

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: MacOS/Python 3.8.7

Does this bug also happen on master? To answer this, you have two options:
See the black playground

Additional context Add any other context about the problem here.

@bbkane bbkane added the T: bug Something isn't working label Feb 7, 2021
@ichard26 ichard26 added T: style What do we want Blackened code to look like? and removed T: bug Something isn't working labels Apr 2, 2021
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label May 30, 2021
@JelleZijlstra
Copy link
Collaborator

Duplicate of #236

@JelleZijlstra JelleZijlstra marked this as a duplicate of #236 Jan 29, 2022
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Jan 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants