I've found that using parentheses (which allow for automatic continuation) instead of \
results in a lot more readable code. The lone exception is using \
with long strings and avoiding a line break at the start of the string.
Worse:
return GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD and LET and THE and HATE and FLOW\
and THROUGH and YOU
Better:
return (GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD and LET and THE and HATE and FLOW
and THROUGH and YOU)
OK:
return """\
GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOD and LET and THE and HATE and FLOW
and THROUGH and YOU"""
Comment From: jorisvandenbossche
xref https://github.com/pydata/pandas/pull/11951#issuecomment-168562469
Comment From: rockg
Part of the underlying issue here is some editors nowadays (e.g., pycharm) have automatic behavior when it comes to continuation and uses '\' continuation by default.
Comment From: wesm
Can that be disabled?
Comment From: rockg
There's an automatic wrap option that will wrap lines automatically with '\' but if the statement was started with '(' then it will wrap without '\'. If one does not wrap automatically then the syntax is up to the user. If a portion of the statement is moved to the next line then '\' is used if not already wrapped in '()'. There is no way to add '()' to these statements by default but this should probably be an editor option. PyDev has no such behavior and relies on the user putting in the appropriate continuation and I'm unsure of other editors.
Comment From: rockg
So, I think if people get in the habit of using '()' at the outset the editor continuation won't be an issue.
Comment From: jbrockmendel
@jorisvandenbossche does black
take care of this for us?
Comment From: jorisvandenbossche
For cases in python code, yes. So I think we can close this. There are some cases in docstrings where we still need it (but that's not the cases discussed above I think)