---
source: crates/ruff_linter/src/rules/flake8_quotes/mod.rs
---
Q004 [*] Unnecessary escape on inner quote character
 --> singles_escaped_unnecessary.py:1:26
  |
1 | this_should_raise_Q004 = "This is a \'string\'"
  |                          ^^^^^^^^^^^^^^^^^^^^^^
2 | this_should_raise_Q004 = "'This' is a \'string\'"
3 | this_is_fine = 'This is a "string"'
  |
help: Remove backslash
  |
  - this_should_raise_Q004 = "This is a \'string\'"
1 + this_should_raise_Q004 = "This is a 'string'"
2 | this_should_raise_Q004 = "'This' is a \'string\'"
  |

Q004 [*] Unnecessary escape on inner quote character
 --> singles_escaped_unnecessary.py:2:26
  |
1 | this_should_raise_Q004 = "This is a \'string\'"
2 | this_should_raise_Q004 = "'This' is a \'string\'"
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^
3 | this_is_fine = 'This is a "string"'
4 | this_is_fine = '\'This\' is a "string"'
  |
help: Remove backslash
  |
1 | this_should_raise_Q004 = "This is a \'string\'"
  - this_should_raise_Q004 = "'This' is a \'string\'"
2 + this_should_raise_Q004 = "'This' is a 'string'"
3 | this_is_fine = 'This is a "string"'
  |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:9:5
   |
 7 | this_should_raise_Q004 = (
 8 |     "This is a"
 9 |     "\'string\'"
   |     ^^^^^^^^^^^^
10 | )
   |
help: Remove backslash
   |
8  |     "This is a"
   -     "\'string\'"
9  +     "'string'"
10 | )
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:13:1
   |
12 | # Same as above, but with f-strings
13 | f"This is a \'string\'"  # Q004
   | ^^^^^^^^^^^^^^^^^^^^^^^
14 | f"'This' is a \'string\'"  # Q004
15 | f'This is a "string"'
   |
help: Remove backslash
   |
12 | # Same as above, but with f-strings
   - f"This is a \'string\'"  # Q004
13 + f"This is a 'string'"  # Q004
14 | f"'This' is a \'string\'"  # Q004
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:14:1
   |
12 | # Same as above, but with f-strings
13 | f"This is a \'string\'"  # Q004
14 | f"'This' is a \'string\'"  # Q004
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
15 | f'This is a "string"'
16 | f'\'This\' is a "string"'
   |
help: Remove backslash
   |
13 | f"This is a \'string\'"  # Q004
   - f"'This' is a \'string\'"  # Q004
14 + f"'This' is a 'string'"  # Q004
15 | f'This is a "string"'
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:21:5
   |
19 | this_should_raise_Q004 = (
20 |     f"This is a"
21 |     f"\'string\'"  # Q004
   |     ^^^^^^^^^^^^^
22 | )
   |
help: Remove backslash
   |
20 |     f"This is a"
   -     f"\'string\'"  # Q004
21 +     f"'string'"  # Q004
22 | )
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:31:1
   |
29 | #
30 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
31 | f"\'foo\' {"foo"}"  # Q004
   | ^^^^^^^^^^^^^^^^^^
32 | f"\'foo\' {f"foo"}"  # Q004
33 | f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
   |
help: Remove backslash
   |
30 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
   - f"\'foo\' {"foo"}"  # Q004
31 + f"'foo' {"foo"}"  # Q004
32 | f"\'foo\' {f"foo"}"  # Q004
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:32:1
   |
30 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
31 | f"\'foo\' {"foo"}"  # Q004
32 | f"\'foo\' {f"foo"}"  # Q004
   | ^^^^^^^^^^^^^^^^^^^
33 | f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
   |
help: Remove backslash
   |
31 | f"\'foo\' {"foo"}"  # Q004
   - f"\'foo\' {f"foo"}"  # Q004
32 + f"'foo' {f"foo"}"  # Q004
33 | f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:33:1
   |
31 | f"\'foo\' {"foo"}"  # Q004
32 | f"\'foo\' {f"foo"}"  # Q004
33 | f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34 |
35 | f"normal {f"nested"} normal"
   |
help: Remove backslash
   |
32 | f"\'foo\' {f"foo"}"  # Q004
   - f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
33 + f"'foo' {f"\'foo\'"} ''"  # Q004
34 |
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:33:12
   |
31 | f"\'foo\' {"foo"}"  # Q004
32 | f"\'foo\' {f"foo"}"  # Q004
33 | f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
   |            ^^^^^^^^^^
34 |
35 | f"normal {f"nested"} normal"
   |
help: Remove backslash
   |
32 | f"\'foo\' {f"foo"}"  # Q004
   - f"\'foo\' {f"\'foo\'"} \'\'"  # Q004
33 + f"\'foo\' {f"'foo'"} \'\'"  # Q004
34 |
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:36:1
   |
35 | f"normal {f"nested"} normal"
36 | f"\'normal\' {f"nested"} normal"  # Q004
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37 | f"\'normal\' {f"nested"} 'single quotes'"
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
   |
help: Remove backslash
   |
35 | f"normal {f"nested"} normal"
   - f"\'normal\' {f"nested"} normal"  # Q004
36 + f"'normal' {f"nested"} normal"  # Q004
37 | f"\'normal\' {f"nested"} 'single quotes'"
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:37:1
   |
35 | f"normal {f"nested"} normal"
36 | f"\'normal\' {f"nested"} normal"  # Q004
37 | f"\'normal\' {f"nested"} 'single quotes'"
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   |
help: Remove backslash
   |
36 | f"\'normal\' {f"nested"} normal"  # Q004
   - f"\'normal\' {f"nested"} 'single quotes'"
37 + f"'normal' {f"nested"} 'single quotes'"
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:38:1
   |
36 | f"\'normal\' {f"nested"} normal"  # Q004
37 | f"\'normal\' {f"nested"} 'single quotes'"
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   |
help: Remove backslash
   |
37 | f"\'normal\' {f"nested"} 'single quotes'"
   - f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
38 + f"'normal' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:38:15
   |
36 | f"\'normal\' {f"nested"} normal"  # Q004
37 | f"\'normal\' {f"nested"} 'single quotes'"
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   |
help: Remove backslash
   |
37 | f"\'normal\' {f"nested"} 'single quotes'"
   - f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
38 + f"\'normal\' {f"'nested' {"other"} normal"} 'single quotes'"  # Q004
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:39:1
   |
37 | f"\'normal\' {f"nested"} 'single quotes'"
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40 |
41 | # Make sure we do not unescape quotes
   |
help: Remove backslash
   |
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
   - f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
39 + f"'normal' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
40 |
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:39:15
   |
37 | f"\'normal\' {f"nested"} 'single quotes'"
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
39 | f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40 |
41 | # Make sure we do not unescape quotes
   |
help: Remove backslash
   |
38 | f"\'normal\' {f"\'nested\' {"other"} normal"} 'single quotes'"  # Q004
   - f"\'normal\' {f"\'nested\' {"other"} 'single quotes'"} normal"  # Q004
39 + f"\'normal\' {f"'nested' {"other"} 'single quotes'"} normal"  # Q004
40 |
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:43:26
   |
41 | # Make sure we do not unescape quotes
42 | this_is_fine = "This is an \\'escaped\\' quote"
43 | this_should_raise_Q004 = "This is an \\\'escaped\\\' quote with an extra backslash"  # Q004
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44 |
45 | # Invalid escapes in bytestrings are also triggered:
   |
help: Remove backslash
   |
42 | this_is_fine = "This is an \\'escaped\\' quote"
   - this_should_raise_Q004 = "This is an \\\'escaped\\\' quote with an extra backslash"  # Q004
43 + this_should_raise_Q004 = "This is an \\'escaped\\' quote with an extra backslash"  # Q004
44 |
   |

Q004 [*] Unnecessary escape on inner quote character
  --> singles_escaped_unnecessary.py:46:5
   |
45 | # Invalid escapes in bytestrings are also triggered:
46 | x = b"\xe7\xeb\x0c\xa1\x1b\x83tN\xce=x\xe9\xbe\x01\xb9\x13B_\xba\xe7\x0c2\xce\'rm\x0e\xcd\xe9.\xf8\xd2"  # Q004
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Remove backslash
   |
45 | # Invalid escapes in bytestrings are also triggered:
   - x = b"\xe7\xeb\x0c\xa1\x1b\x83tN\xce=x\xe9\xbe\x01\xb9\x13B_\xba\xe7\x0c2\xce\'rm\x0e\xcd\xe9.\xf8\xd2"  # Q004
46 + x = b"\xe7\xeb\x0c\xa1\x1b\x83tN\xce=x\xe9\xbe\x01\xb9\x13B_\xba\xe7\x0c2\xce'rm\x0e\xcd\xe9.\xf8\xd2"  # Q004
   |
