---
source: crates/ruff_linter/src/rules/flake8_quotes/mod.rs
---
Q004 [*] Unnecessary escape on inner quote character
 --> doubles_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
 --> doubles_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
 --> doubles_escaped_unnecessary.py:3:16
  |
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'"
5 | this_is_fine = "\"This\" is a 'string'"
  |
help: Remove backslash
  |
2 | this_should_raise_Q004 = 'This is \\ a \\\"string\"'
  - this_is_fine = '"This" is a \"string\"'
3 + this_is_fine = '"This" is a "string"'
4 | this_is_fine = "This is a 'string'"
  |

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

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

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

Q004 [*] Unnecessary escape on inner quote character
  --> doubles_escaped_unnecessary.py:16:1
   |
14 | f'This is a \"string\"'  # Q004
15 | f'This is \\ a \\\"string\"'  # Q004
16 | f'"This" is a \"string\"'
   | ^^^^^^^^^^^^^^^^^^^^^^^^^
17 | f"This is a 'string'"
18 | f"\"This\" is a 'string'"
   |
help: Remove backslash
   |
15 | f'This is \\ a \\\"string\"'  # Q004
   - f'"This" is a \"string\"'
16 + f'"This" is a "string"'
17 | f"This is a 'string'"
   |

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

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

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

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

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

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

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

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

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

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

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

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