dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.49k stars 54 forks source link

[Bug]: False positive match for rule FURB183 when there's nested curly braces in an f string #314

Closed owenlamont closed 11 months ago

owenlamont commented 11 months ago

Has your issue already been fixed?

The Bug

The following code:

f"{timestamp:{timestamp_fmt}} ({time_since_str} ago)"

Emits the following error:

$ refurb file.py
[FURB183]: Replace `f"{timestamp_fmt}"` with `str(timestamp_fmt)`

But it should not be emitting an error instance because...

Refurb rule FURB183 gets a false positive when there are nested curly braces in an fstring

Version Info

1.25.0

Python Version

3.11.2

Config File

[tool.refurb]
ignore = [
    "FURB124", # Ignore rule to recommend chaining comparisons over anding pairs
    "FURB140", # Ignore rule to prefer starmap when iterating and constructing
    "FURB152", # Ignore rule to replace number literals that look like math constants
]
python_version = "3.9"

Extra Info

None

dosisod commented 11 months ago

@owenlamont Thank you for reporting this!

owenlamont commented 11 months ago

Thanks for resolving this so fast!