MichaelKim0407 / flake8-use-fstring

MIT License
51 stars 7 forks source link

Should not trigger on byte strings #22

Closed ghost closed 2 years ago

ghost commented 2 years ago

The following code triggers an FS001 error:

a = 42
b"y=%d" % a

However, using an f-string with a byte string is a syntax error:

>>> bf"y={a}"
  File "<stdin>", line 1
    bf"y={a}"
      ^^^^^^^
SyntaxError: invalid syntax

(In this particular case f"y={a}".encode("utf-8") would work, but that's longer and doesn't always work correctly if there are byte literals in my string.)

MichaelKim0407 commented 2 years ago

OK I can take a look. Should be relatively easy to change.

Can you please check what greedy level you are using? If you are using level 2 then it would report an error anyway.

ghost commented 2 years ago

I'm using whatever is the default.