Flake8 has no opinion about multiline strings at all. Everything in this example is correct:
def f():
a = """
text
text
"""
a = """
text
text
"""
a = """text
text
"""
a = """text
text"""
a = """
text
text
"""
return a
And so on.
Let's choose the only option.
I vote for the second one:
def f():
something = """
text
text
"""
Because it matches with braces style by PEP-8:
def f():
something = (
text,
text,
)
Consistency and readability. Let's not allow to break block indentation in such a rough way.
The motivation behind allowing such awful things is newlines and indentation preserving in multiline strings. However, you should never rely on it because that variable could be moved in constants, function turned into a method, part of the code wrapped into with statement, and a lot more ways how indentation for statement can be changed. So, always use textwrap.dedent, textwrap.indent, and str.strip to get expected indentation and newlines for a multiline string.
Awesome!
I see two viable cases:
def test():
"""Docstring."""
def test():
"""
First line.
Details.
"""
x = """some text
lines.
"""
Docstrings shouldn't be checked in this violation. There are a lot of plugins that do it by a lot more of much smarter rules.
@orsinium agreed.
@orsinium Since you said that a lot of other plugins have much smarter rules for this functionality, does that mean you don't want this change? Should this issue be closed or does it still need to be addressed?
Still needs, @andreaestrada. But just not the docstring part.
Only
def test():
x = """
a
"""
vs
def test():
x = """
a
"""
The rule should check all multiline strings except docstrings. Docstrings are checked by other plugins, multiline strings checked by none of them.
Hi, I did some research on this issue and I might have figured out the solution for the assignment case - check indentation against the indentation of two tokens before.
Other usages I thought about, that is comparisons and function calls, look tricky. Shall multiline strings be allowed to use directly (without assigning to a variable)?
Thanks a lot!
Shall multiline strings be allowed to use directly (without assigning to a variable)?
Nope, looks quite unreadable.
Cool, then if you let me do it, I can work on these two multiline string violations
Or should they be joined / there is something else I haven't thought about?
I would say these two are different violation. The first one is the best practice, the second one is consistency.
Okay, thank you!