-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
noqa comments for strings goes at the end of it. Similarly, for multi-line strings (triple-quoted), the noqa directive is expected on the last line of the string.
Now, with the new f-string specification, multi-line expressions are allowed in a single-quoted f-string. For example, the following code is valid in Python 3.12 but invalid before 3.12:
f"foo {
a
*
b
}"We need to make sure to add the noqa directives at the end of f-string regardless if it's single or triple-quoted. For the above example, the outcome would be:
f"foo {
a
*
b
}" # noqa: F821The extract_noqa_line_for function needs to be updated to fix this. Currently, it only checks for tripled-quoted strings using the String token. Now, we will need to use the FStringStart token to (1) check if it's a tripled-quoted f-string, if it is then (2) get the end range of the corresponding FStringEnd token. This could be done by either using a stack or using the Indexer to get the f-string range.