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

Improve formatting for multiline strings wrapped by parentheses with a method call #2113

Open
ichard26 opened this issue Apr 16, 2021 · 1 comment
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. T: style What do we want Blackened code to look like?

Comments

@ichard26
Copy link
Collaborator

ichard26 commented Apr 16, 2021

Describe the style change

Multiline strings wrapped by parentheses with a method call are formatted in a questionable way. While I'm not sure what would be the best output, the desired style I provided is probably a good next step. The main point is to strip the unnecessary parentheses which cause Black to do some ... questionably looking stuff.

Examples in the current Black style

  def case1():
    (""" this is a multi-line
    string that is pretty poorly formatted
    """).method(args)


def case2():
    foo = ("""
a""").format(argument)


def case3():
    details = ("""%s
                  %s
               """) % (a, b)

to:

def case1():
    (
        """ this is a multi-line
    string that is pretty poorly formatted
    """
    ).method(args)


def case2():
    foo = (
        """
a"""
    ).format(argument)


def case3():
    details = (
        (
            """%s
                  %s
               """
        )
        % (a, b)
    )

Desired style (open to debate)

def case1():
    """ this is a multi-line
    string that is pretty poorly formatted
    """.method(args)


def case2():
    foo = """
a""".format(argument)


def case3():
    details = """%s
                  %s
               """ % (a, b)

Additional context

The desired style depends on GH-256 being resolved first.

The examples provided here are from instability issues: GH-958 & GH-954. The examples are no longer unstable, but their reformatted equivalents aren't good, hence this issue.

@ichard26 ichard26 added T: style What do we want Blackened code to look like? F: parentheses Too many parentheses, not enough parentheses, and so on. labels Apr 16, 2021
@0xallie
Copy link

0xallie commented Jul 11, 2021

Indeed, the current behavior is pretty awkward with sqlite3 statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

1 participant