Open lczech opened 4 months ago
Just ran into a similar, but slightly different variant of this while trying to format another file.
Minimal example:
if condition_1:
include: "rule_1.smk"
elif condition_2:
pass
else:
raise Exception("Invalid conditions")
Fails with
snakefmt.exceptions.InvalidPython: Black error:
Cannot parse: 1:0: elif condition_2:
(Note reported line number may be incorrect, as snakefmt could not determine the true line number)
Here, removing either the elif
, or the else
branch then works. However, interestingly, it also works to replace the pass
under condition 2 by another include
statement:
if condition_1:
include: "rule_1.smk"
elif condition_2:
include: "dummy.smk"
else:
raise Exception("Invalid conditions")
This works.
Oh, very weird. I'll take a look soon hopefully.
I think this is a regression of https://github.com/snakemake/snakefmt/issues/115, or an extension of the issue reported there.
Minimal example, using snakefmt v0.10.2:
The error is:
Removing the second conditional part however solves this, despite that part not having anything to do with the condition that causes the problem.
My current workaround is to rewrite the
else
branch asbut since in my actual code I have a few
elif
befor that, this is quite cumbersome.