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

ℹ Safe fix
1   |-this_should_raise_Q004 = 'This is a \"string\"'
  1 |+this_should_raise_Q004 = 'This is a "string"'
2 2 | this_should_raise_Q004 = 'This is \\ a \\\"string\"'
3 3 | this_is_fine = '"This" is a \"string\"'
4 4 | this_is_fine = "This is a 'string'"

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

ℹ Safe fix
1 1 | this_should_raise_Q004 = 'This is a \"string\"'
2   |-this_should_raise_Q004 = 'This is \\ a \\\"string\"'
  2 |+this_should_raise_Q004 = 'This is \\ a \\"string"'
3 3 | this_is_fine = '"This" is a \"string\"'
4 4 | this_is_fine = "This is a 'string'"
5 5 | this_is_fine = "\"This\" is a 'string'"

doubles_escaped_unnecessary.py:3:16: Q004 [*] Unnecessary escape on inner quote character
  |
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\"'
  |                ^^^^^^^^^^^^^^^^^^^^^^^^ Q004
4 | this_is_fine = "This is a 'string'"
5 | this_is_fine = "\"This\" is a 'string'"
  |
  = help: Remove backslash

ℹ Safe fix
1 1 | this_should_raise_Q004 = 'This is a \"string\"'
2 2 | this_should_raise_Q004 = 'This is \\ a \\\"string\"'
3   |-this_is_fine = '"This" is a \"string\"'
  3 |+this_is_fine = '"This" is a "string"'
4 4 | this_is_fine = "This is a 'string'"
5 5 | this_is_fine = "\"This\" is a 'string'"
6 6 | this_is_fine = r'This is a \"string\"'

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

ℹ Safe fix
7  7  | this_is_fine = R'This is a \"string\"'
8  8  | this_should_raise_Q004 = (
9  9  |     'This is a'
10    |-    '\"string\"'
   10 |+    '"string"'
11 11 | )
12 12 | 
13 13 | # Same as above, but with f-strings

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

ℹ Safe fix
11 11 | )
12 12 | 
13 13 | # Same as above, but with f-strings
14    |-f'This is a \"string\"'  # Q004
   14 |+f'This is a "string"'  # Q004
15 15 | f'This is \\ a \\\"string\"'  # Q004
16 16 | f'"This" is a \"string\"'
17 17 | f"This is a 'string'"

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

ℹ Safe fix
12 12 | 
13 13 | # Same as above, but with f-strings
14 14 | f'This is a \"string\"'  # Q004
15    |-f'This is \\ a \\\"string\"'  # Q004
   15 |+f'This is \\ a \\"string"'  # Q004
16 16 | f'"This" is a \"string\"'
17 17 | f"This is a 'string'"
18 18 | f"\"This\" is a 'string'"

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

ℹ Safe fix
13 13 | # Same as above, but with f-strings
14 14 | f'This is a \"string\"'  # Q004
15 15 | f'This is \\ a \\\"string\"'  # Q004
16    |-f'"This" is a \"string\"'
   16 |+f'"This" is a "string"'
17 17 | f"This is a 'string'"
18 18 | f"\"This\" is a 'string'"
19 19 | fr'This is a \"string\"'

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

ℹ Safe fix
20 20 | fR'This is a \"string\"'
21 21 | this_should_raise_Q004 = (
22 22 |     f'This is a'
23    |-    f'\"string\"'  # Q004
   23 |+    f'"string"'  # Q004
24 24 | )
25 25 | 
26 26 | # Nested f-strings (Python 3.12+)

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

ℹ Safe fix
30 30 | #   f"'foo' {'nested'}"
31 31 | #
32 32 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
33    |-f'\"foo\" {'nested'}'  # Q004
   33 |+f'"foo" {'nested'}'  # Q004
34 34 | f'\"foo\" {f'nested'}'  # Q004
35 35 | f'\"foo\" {f'\"nested\"'} \"\"'  # Q004
36 36 | 

doubles_escaped_unnecessary.py:34:1: Q004 [*] Unnecessary escape on inner quote character
   |
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
   | ^^^^^^^^^^^^^^^^^^^^^^ Q004
35 | f'\"foo\" {f'\"nested\"'} \"\"'  # Q004
   |
   = help: Remove backslash

ℹ Safe fix
31 31 | #
32 32 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
33 33 | f'\"foo\" {'nested'}'  # Q004
34    |-f'\"foo\" {f'nested'}'  # Q004
   34 |+f'"foo" {f'nested'}'  # Q004
35 35 | f'\"foo\" {f'\"nested\"'} \"\"'  # Q004
36 36 | 
37 37 | f'normal {f'nested'} normal'

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

ℹ Safe fix
32 32 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
33 33 | f'\"foo\" {'nested'}'  # Q004
34 34 | f'\"foo\" {f'nested'}'  # Q004
35    |-f'\"foo\" {f'\"nested\"'} \"\"'  # Q004
   35 |+f'"foo" {f'\"nested\"'} ""'  # Q004
36 36 | 
37 37 | f'normal {f'nested'} normal'
38 38 | f'\"normal\" {f'nested'} normal'  # Q004

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

ℹ Safe fix
32 32 | # but as the actual string itself is invalid pre 3.12, we don't catch it.
33 33 | f'\"foo\" {'nested'}'  # Q004
34 34 | f'\"foo\" {f'nested'}'  # Q004
35    |-f'\"foo\" {f'\"nested\"'} \"\"'  # Q004
   35 |+f'\"foo\" {f'"nested"'} \"\"'  # Q004
36 36 | 
37 37 | f'normal {f'nested'} normal'
38 38 | f'\"normal\" {f'nested'} normal'  # Q004

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

ℹ Safe fix
35 35 | f'\"foo\" {f'\"nested\"'} \"\"'  # Q004
36 36 | 
37 37 | f'normal {f'nested'} normal'
38    |-f'\"normal\" {f'nested'} normal'  # Q004
   38 |+f'"normal" {f'nested'} normal'  # Q004
39 39 | f'\"normal\" {f'nested'} "double quotes"'
40 40 | f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
41 41 | f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004

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

ℹ Safe fix
36 36 | 
37 37 | f'normal {f'nested'} normal'
38 38 | f'\"normal\" {f'nested'} normal'  # Q004
39    |-f'\"normal\" {f'nested'} "double quotes"'
   39 |+f'"normal" {f'nested'} "double quotes"'
40 40 | f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
41 41 | f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004
42 42 | 

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

ℹ Safe fix
37 37 | f'normal {f'nested'} normal'
38 38 | f'\"normal\" {f'nested'} normal'  # Q004
39 39 | f'\"normal\" {f'nested'} "double quotes"'
40    |-f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
   40 |+f'"normal" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
41 41 | f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004
42 42 | 
43 43 | # Make sure we do not unescape quotes

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

ℹ Safe fix
37 37 | f'normal {f'nested'} normal'
38 38 | f'\"normal\" {f'nested'} normal'  # Q004
39 39 | f'\"normal\" {f'nested'} "double quotes"'
40    |-f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
   40 |+f'\"normal\" {f'"nested" {'other'} normal'} "double quotes"'  # Q004
41 41 | f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004
42 42 | 
43 43 | # Make sure we do not unescape quotes

doubles_escaped_unnecessary.py:41:1: Q004 [*] Unnecessary escape on inner quote character
   |
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
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q004
42 | 
43 | # Make sure we do not unescape quotes
   |
   = help: Remove backslash

ℹ Safe fix
38 38 | f'\"normal\" {f'nested'} normal'  # Q004
39 39 | f'\"normal\" {f'nested'} "double quotes"'
40 40 | f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
41    |-f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004
   41 |+f'"normal" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004
42 42 | 
43 43 | # Make sure we do not unescape quotes
44 44 | this_is_fine = 'This is an \\"escaped\\" quote'

doubles_escaped_unnecessary.py:41:15: Q004 [*] Unnecessary escape on inner quote character
   |
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
   |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q004
42 | 
43 | # Make sure we do not unescape quotes
   |
   = help: Remove backslash

ℹ Safe fix
38 38 | f'\"normal\" {f'nested'} normal'  # Q004
39 39 | f'\"normal\" {f'nested'} "double quotes"'
40 40 | f'\"normal\" {f'\"nested\" {'other'} normal'} "double quotes"'  # Q004
41    |-f'\"normal\" {f'\"nested\" {'other'} "double quotes"'} normal'  # Q004
   41 |+f'\"normal\" {f'"nested" {'other'} "double quotes"'} normal'  # Q004
42 42 | 
43 43 | # Make sure we do not unescape quotes
44 44 | this_is_fine = 'This is an \\"escaped\\" quote'

doubles_escaped_unnecessary.py:45:26: Q004 [*] Unnecessary escape on inner quote character
   |
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'
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Q004
   |
   = help: Remove backslash

ℹ Safe fix
42 42 | 
43 43 | # Make sure we do not unescape quotes
44 44 | this_is_fine = 'This is an \\"escaped\\" quote'
45    |-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'


