-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Opinion: Unwanted indentation of multiline string #233
Comments
I encountered the same issue with calls to |
No. Black never hugs arguments to parentheses. Think of the opening triple quotes like an opening bracket. Black wouldn't keep it on the same line with another opening bracket. Instead of using this formatting: def get_stuff(cr, value):
cr.execute("""
SELECT whatever
FROM some_table t
WHERE id = %s
""", [value])
return cr.fetchone() Black considers this a better formatting: def get_stuff(cr, value):
cr.execute(
"""
SELECT whatever
FROM some_table t
WHERE id = %s
""",
[value],
)
return cr.fetchone() This is symmetrical to something like: def get_stuff(cr, value):
cr.execute(
(
'SELECT whatever '
'FROM some_table t '
'WHERE id = %s'
),
[value],
)
return cr.fetchone() Unfortunately it's not safe for Black to change indentation within your multiline strings, so that it up to you. |
I tend to write my SQL queries using this formatting.
However,
black --diff
produce the following outputWhich I find less readable, unpleasant.
Shouldn't
black
keep a multiline string first argument on the same line? (unless the line is too long, obviously)The text was updated successfully, but these errors were encountered: