snakemake / snakefmt

The uncompromising Snakemake code formatter
MIT License
151 stars 29 forks source link

Incorrectly removes double curly braces in f-string #215

Closed johanneskoester closed 9 months ago

johanneskoester commented 9 months ago

The following:

def get_test_regions(wildcards):
    benchmark = config["variant-calls"][wildcards.callset]["benchmark"]
    return f"resources/regions/{benchmark}/test-regions.cov-{{cov}}.bed"

get incorrectly reformatted to

def get_test_regions(wildcards):
    benchmark = config["variant-calls"][wildcards.callset]["benchmark"]
    return f"resources/regions/{benchmark}/test-regions.cov-{cov}.bed"

(double curly braces are removed) This is a pretty severe bug as it alters the logic of the code and leads to unexpected errors.

mbhall88 commented 9 months ago

This isn't precisely a snakefmt problem. I relates to #207 and python the way in which python 3.12 tokenizes f-strings (this is formatted correctly in python 3.10).

Nevertheless, it is a bug. I'll try and get on to it ASAP. I started a discussion in the development channel on the snakemake discord about the future of dealing with bugs etc in this repo and it would be good to have your input @johanneskoester

johanneskoester commented 9 months ago

Somebody who can probably give valuable input here could be @Hocnonsense who fixed f-string handling for Python 3.12 in Snakemake itself.