MichaelKim0407 / flake8-use-fstring

MIT License
51 stars 7 forks source link

Should not trigger when format expression contains backslash #21

Closed ghost closed 2 years ago

ghost commented 2 years ago

The following code triggers an FS002 error:

"x={}".format(s.replace("\\", "/"))

However, attempting to change it to an f-string results in a syntax error:

f"x={s.replace('\\', '/')}"
SyntaxError: f-string expression part cannot include a backslash
MichaelKim0407 commented 2 years ago

To be honest I think this issue is out of scope.

This plugin simply checks if .format is used. It does not analyze the syntax or the lexical structure. To correctly cover this kind of edge case would make the implementation way too complicated.

You can use #noqa to disable checking on this line. Or you can break the statement into two lines.