This is a minimal example based on my code:
def fn(self):
Foo() \
.with_bar(
Bar()
.with_baz('Baz')
)
I find this quite readable, but pycodestyle
complains:
stdin:5:17: E131 continuation line unaligned for hanging indent
In almost every case pycodestyle
reports issues which, when fixed, improve the readability of the code. However, this time the following code seems to be the only accepted solution:
def fn(self):
Foo() \
.with_bar(
Bar()
.with_baz('Baz')
)
This seems much less readable: the indentation is inconsistent with the default continuation indentation used for Foo
, and it makes .with_baz('Baz')
look like a parameter to with_bar
. Is this something I should simply get used to, is it a bug in pycodestyle
, or is there an alternative formatting which conserves the general style of breaking up subsequent with_*
calls that is PEP 8 compatible?
(Please imagine there are more with
methods on both Foo
and Bar
- the whole thing is a builder pattern which needs to be split into multiple lines to be PEP 8 compatible and pleasant to read. I cannot simply join the lines to fix the issue. Pulling out the Bar
as a variable is of course an option, but that's beside the point.)