Comment in multi-line parenthesis breaks Black
This might be an issue with Black, but not sure.
Minimal example:
rule my_rule:
input:
data=(
# a comment on the below
"input_1.txt"
if condition
else "input_2.txt"
)
Obviously, this is not good style, and the comment should go before the the data line anyway - which is what I'll do to fix this. However, it still should not break the formatting.
Error:
snakefmt.exceptions.InvalidPython: Black error:
Cannot parse: 2:0: EOF in multi-line statement
Python itself does not complain about this, and so I think neither should do the formatter, despite the bad style, and instead just simply move the comment up, as it does in similar situations without parenthesis.
I suspect this is not a black issue, but an issue with the way we pass it to black.
Another example of the same problem:
rule a:
input:
expand(
"foo",
test=[1, 2, 3], # comment
)
As this is quite a common case, @mbhall88 do you have a pointer for us how to fix this?
I think @bricoletc did most of the work dealing with comments…
Off the top,of my head I wouldn’t know. Essentially what I normally do to fix these things is add a failing minimal test case and then walk through with the debugger to find where in the code the comment is causing issues.
Sorry, am on parental leave so don’t have time to debug this myself at the moment