---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF027 [*] Possible f-string without an `f` prefix
 --> RUF027_0.py:5:7
  |
3 | "always ignore this: {val}"
4 |
5 | print("but don't ignore this: {val}")  # RUF027
  |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: Add `f` prefix
  |
4 |
  - print("but don't ignore this: {val}")  # RUF027
5 + print(f"but don't ignore this: {val}")  # RUF027
6 |
  |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:10:9
   |
 8 | def simple_cases():
 9 |     a = 4
10 |     b = "{a}"  # RUF027
   |         ^^^^^
11 |     c = "{a} {b} f'{val}' "  # RUF027
   |
help: Add `f` prefix
   |
9  |     a = 4
   -     b = "{a}"  # RUF027
10 +     b = f"{a}"  # RUF027
11 |     c = "{a} {b} f'{val}' "  # RUF027
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:11:9
   |
 9 |     a = 4
10 |     b = "{a}"  # RUF027
11 |     c = "{a} {b} f'{val}' "  # RUF027
   |         ^^^^^^^^^^^^^^^^^^^
   |
help: Add `f` prefix
   |
10 |     b = "{a}"  # RUF027
   -     c = "{a} {b} f'{val}' "  # RUF027
11 +     c = f"{a} {b} f'{val}' "  # RUF027
12 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:21:9
   |
19 | def raw_string():
20 |     a = 4
21 |     b = r"raw string with formatting: {a}"  # RUF027
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22 |     c = r"raw string with \backslashes\ and \"escaped quotes\": {a}"  # RUF027
   |
help: Add `f` prefix
   |
20 |     a = 4
   -     b = r"raw string with formatting: {a}"  # RUF027
21 +     b = fr"raw string with formatting: {a}"  # RUF027
22 |     c = r"raw string with \backslashes\ and \"escaped quotes\": {a}"  # RUF027
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:22:9
   |
20 |     a = 4
21 |     b = r"raw string with formatting: {a}"  # RUF027
22 |     c = r"raw string with \backslashes\ and \"escaped quotes\": {a}"  # RUF027
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Add `f` prefix
   |
21 |     b = r"raw string with formatting: {a}"  # RUF027
   -     c = r"raw string with \backslashes\ and \"escaped quotes\": {a}"  # RUF027
22 +     c = fr"raw string with \backslashes\ and \"escaped quotes\": {a}"  # RUF027
23 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:27:11
   |
25 | def print_name(name: str):
26 |     a = 4
27 |     print("Hello, {name}!")  # RUF027
   |           ^^^^^^^^^^^^^^^^
28 |     print("The test value we're using today is {a}")  # RUF027
   |
help: Add `f` prefix
   |
26 |     a = 4
   -     print("Hello, {name}!")  # RUF027
27 +     print(f"Hello, {name}!")  # RUF027
28 |     print("The test value we're using today is {a}")  # RUF027
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:28:11
   |
26 |     a = 4
27 |     print("Hello, {name}!")  # RUF027
28 |     print("The test value we're using today is {a}")  # RUF027
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Add `f` prefix
   |
27 |     print("Hello, {name}!")  # RUF027
   -     print("The test value we're using today is {a}")  # RUF027
28 +     print(f"The test value we're using today is {a}")  # RUF027
29 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:33:33
   |
31 | def nested_funcs():
32 |     a = 4
33 |     print(do_nothing(do_nothing("{a}")))  # RUF027
   |                                 ^^^^^
   |
help: Add `f` prefix
   |
32 |     a = 4
   -     print(do_nothing(do_nothing("{a}")))  # RUF027
33 +     print(do_nothing(do_nothing(f"{a}")))  # RUF027
34 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:39:19
   |
37 |     a = 4
38 |     c = a
39 |     single_line = """ {a} """  # RUF027
   |                   ^^^^^^^^^^^
40 |     # RUF027
41 |     multi_line = a = """b { # comment
   |
help: Add `f` prefix
   |
38 |     c = a
   -     single_line = """ {a} """  # RUF027
39 +     single_line = f""" {a} """  # RUF027
40 |     # RUF027
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:41:22
   |
39 |       single_line = """ {a} """  # RUF027
40 |       # RUF027
41 |       multi_line = a = """b { # comment
   |  ______________________^
42 | |     c}  d
43 | |     """
   | |_______^
   |
help: Add `f` prefix
   |
40 |     # RUF027
   -     multi_line = a = """b { # comment
41 +     multi_line = a = f"""b { # comment
42 |     c}  d
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:49:9
   |
47 |       a = 4
48 |       # RUF027
49 |       b = " {\
   |  _________^
50 | |     a} \
51 | |     "
   | |_____^
   |
help: Add `f` prefix
   |
48 |     # RUF027
   -     b = " {\
49 +     b = f" {\
50 |     a} \
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:56:9
   |
54 | def implicit_concat():
55 |     a = 4
56 |     b = "{a}" "+" "{b}" r" \\ "  # RUF027 for the first part only
   |         ^^^^^
57 |     print(f"{a}" "{a}" f"{b}")  # RUF027
   |
help: Add `f` prefix
   |
55 |     a = 4
   -     b = "{a}" "+" "{b}" r" \\ "  # RUF027 for the first part only
56 +     b = f"{a}" "+" "{b}" r" \\ "  # RUF027 for the first part only
57 |     print(f"{a}" "{a}" f"{b}")  # RUF027
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:57:18
   |
55 |     a = 4
56 |     b = "{a}" "+" "{b}" r" \\ "  # RUF027 for the first part only
57 |     print(f"{a}" "{a}" f"{b}")  # RUF027
   |                  ^^^^^
   |
help: Add `f` prefix
   |
56 |     b = "{a}" "+" "{b}" r" \\ "  # RUF027 for the first part only
   -     print(f"{a}" "{a}" f"{b}")  # RUF027
57 +     print(f"{a}" f"{a}" f"{b}")  # RUF027
58 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:62:9
   |
60 | def escaped_chars():
61 |     a = 4
62 |     b = "\"not escaped:\" '{a}' \"escaped:\": '{{c}}'"  # RUF027
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Add `f` prefix
   |
61 |     a = 4
   -     b = "\"not escaped:\" '{a}' \"escaped:\": '{{c}}'"  # RUF027
62 +     b = f"\"not escaped:\" '{a}' \"escaped:\": '{{c}}'"  # RUF027
63 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:70:18
   |
68 |     first = "Wendy"
69 |     last = "Appleseed"
70 |     value.method("{first} {last}")  # RUF027
   |                  ^^^^^^^^^^^^^^^^
71 |
72 | def format_specifiers():
   |
help: Add `f` prefix
   |
69 |     last = "Appleseed"
   -     value.method("{first} {last}")  # RUF027
70 +     value.method(f"{first} {last}")  # RUF027
71 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:74:9
   |
72 | def format_specifiers():
73 |     a = 4
74 |     b = "{a:b} {a:^5}"
   |         ^^^^^^^^^^^^^^
75 |
76 | # fstrings are never correct as type definitions
   |
help: Add `f` prefix
   |
73 |     a = 4
   -     b = "{a:b} {a:^5}"
74 +     b = f"{a:b} {a:^5}"
75 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
  --> RUF027_0.py:92:11
   |
90 | def backslash_test():
91 |     x = "test"
92 |     print("Hello {'\\n'}{x}")  # Should not trigger RUF027 for Python < 3.12
   |           ^^^^^^^^^^^^^^^^^^
93 |
94 | # Test case for comment handling in f-string interpolations
   |
help: Add `f` prefix
   |
91 |     x = "test"
   -     print("Hello {'\\n'}{x}")  # Should not trigger RUF027 for Python < 3.12
92 +     print(f"Hello {'\\n'}{x}")  # Should not trigger RUF027 for Python < 3.12
93 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
   --> RUF027_0.py:98:11
    |
 96 |   def comment_test():
 97 |       x = "!"
 98 |       print("""{x  # }
    |  ___________^
 99 | | }""")
    | |____^
100 |
101 |   # Test case for `#` inside a nested string literal in interpolation
    |
help: Add `f` prefix
   |
97 |     x = "!"
   -     print("""{x  # }
98 +     print(f"""{x  # }
99 | }""")
   |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
   --> RUF027_0.py:105:11
    |
103 | def hash_in_string_test():
104 |     x = "world"
105 |     print("Hello {'#'}{x}")   # RUF027: `#` is inside a string, not a comment
    |           ^^^^^^^^^^^^^^^^
106 |     print("Hello {\"#\"}{x}") # RUF027: same, double-quoted
    |
help: Add `f` prefix
    |
104 |     x = "world"
    -     print("Hello {'#'}{x}")   # RUF027: `#` is inside a string, not a comment
105 +     print(f"Hello {'#'}{x}")   # RUF027: `#` is inside a string, not a comment
106 |     print("Hello {\"#\"}{x}") # RUF027: same, double-quoted
    |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
   --> RUF027_0.py:112:11
    |
110 | def hash_in_format_spec_test():
111 |     n = 255
112 |     print("Hex: {n:#x}")   # RUF027: `#` is in format spec, not a comment
    |           ^^^^^^^^^^^^^
113 |     print("Oct: {n:#o}")   # RUF027: same
    |
help: Add `f` prefix
    |
111 |     n = 255
    -     print("Hex: {n:#x}")   # RUF027: `#` is in format spec, not a comment
112 +     print(f"Hex: {n:#x}")   # RUF027: `#` is in format spec, not a comment
113 |     print("Oct: {n:#o}")   # RUF027: same
    |
note: This is an unsafe fix and may change runtime behavior

RUF027 [*] Possible f-string without an `f` prefix
   --> RUF027_0.py:113:11
    |
111 |     n = 255
112 |     print("Hex: {n:#x}")   # RUF027: `#` is in format spec, not a comment
113 |     print("Oct: {n:#o}")   # RUF027: same
    |           ^^^^^^^^^^^^^
114 |
115 | # Test case for `#` in nested interpolation inside format spec (e.g., `{1:{x #}}`)
    |
help: Add `f` prefix
    |
112 |     print("Hex: {n:#x}")   # RUF027: `#` is in format spec, not a comment
    -     print("Oct: {n:#o}")   # RUF027: same
113 +     print(f"Oct: {n:#o}")   # RUF027: same
114 |
    |
note: This is an unsafe fix and may change runtime behavior
