flake8-quotes icon indicating copy to clipboard operation
flake8-quotes copied to clipboard

Incorrect Q003 error

Open jonyscathe opened this issue 1 year ago • 3 comments

Since 3.4.0 came out I am getting Q003 errors on code such as:

string = f'My id is {some_dictionary['id']}'

As per f-string changes in python 3.12 it is possible to now use the any quotes within the f-string expression without escaping first. This code was not flagging before 3.4.0. It really shouldn't be flagged given that there are no escaped inner quotes here.

jonyscathe avatar Feb 14 '24 00:02 jonyscathe

Hi. You should be able to use the (default off) flag --check-inside-f-strings to make this work.

arnimarj avatar Feb 14 '24 16:02 arnimarj

Thanks for the quick reply. If I enable that flag as you suggest then my Q003 error goes away, but I am now getting erroneous Q000 errors on f-strings that contain a single quote within the string. For example, with the --check-inside-f-strings I am getting Q000 Double quotes found but single quotes preferred on:

string = f"Name {test_name} doesn't exist."

jonyscathe avatar Feb 15 '24 07:02 jonyscathe

You are right. I have an experimental branch over at https://github.com/zheller/flake8-quotes/pull/120. I'll investigate in depth a bit later.

arnimarj avatar Feb 15 '24 11:02 arnimarj