---
source: crates/ruff_linter/src/rules/refurb/mod.rs
---
FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:10:9
   |
 8 |   def _():
 9 |       with open("file", "w") as f:
10 | /         for line in lines:
11 | |             f.write(line)
   | |_________________________^
   |
help: Replace with `f.writelines`
   |
9  |     with open("file", "w") as f:
   -         for line in lines:
   -             f.write(line)
10 +         f.writelines(lines)
11 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:17:9
   |
15 |       other_line = "other line"
16 |       with Path("file").open("w") as f:
17 | /         for line in lines:
18 | |             f.write(other_line)
   | |_______________________________^
   |
help: Replace with `f.writelines`
   |
16 |     with Path("file").open("w") as f:
   -         for line in lines:
   -             f.write(other_line)
17 +         f.writelines(other_line for line in lines)
18 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:23:9
   |
21 |   def _():
22 |       with Path("file").open("w") as f:
23 | /         for line in lines:
24 | |             f.write(line)
   | |_________________________^
   |
help: Replace with `f.writelines`
   |
22 |     with Path("file").open("w") as f:
   -         for line in lines:
   -             f.write(line)
23 +         f.writelines(lines)
24 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:29:9
   |
27 |   def _():
28 |       with Path("file").open("wb") as f:
29 | /         for line in lines:
30 | |             f.write(line.encode())
   | |__________________________________^
   |
help: Replace with `f.writelines`
   |
28 |     with Path("file").open("wb") as f:
   -         for line in lines:
   -             f.write(line.encode())
29 +         f.writelines(line.encode() for line in lines)
30 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:35:9
   |
33 |   def _():
34 |       with Path("file").open("w") as f:
35 | /         for line in lines:
36 | |             f.write(line.upper())
   | |_________________________________^
   |
help: Replace with `f.writelines`
   |
34 |     with Path("file").open("w") as f:
   -         for line in lines:
   -             f.write(line.upper())
35 +         f.writelines(line.upper() for line in lines)
36 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:43:9
   |
41 |           pass
42 |
43 | /         for line in lines:
44 | |             f.write(line)
   | |_________________________^
   |
help: Replace with `f.writelines`
   |
42 |
   -         for line in lines:
   -             f.write(line)
43 +         f.writelines(lines)
44 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:50:9
   |
48 |       # Offer unsafe fix if it would delete comments
49 |       with open("file","w") as f:
50 | /         for line in lines:
51 | |             # a really important comment
52 | |             f.write(line)
   | |_________________________^
   |
help: Replace with `f.writelines`
   |
49 |     with open("file","w") as f:
   -         for line in lines:
   -             # a really important comment
   -             f.write(line)
50 +         f.writelines(lines)
51 |
   |
note: This is an unsafe fix and may change runtime behavior

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:57:9
   |
55 |   def _():
56 |       with open("file", "w") as f:
57 | /         for () in a:
58 | |             f.write(())
   | |_______________________^
   |
help: Replace with `f.writelines`
   |
56 |     with open("file", "w") as f:
   -         for () in a:
   -             f.write(())
57 +         f.writelines(() for () in a)
58 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:63:9
   |
61 |   def _():
62 |       with open("file", "w") as f:
63 | /         for a, b, c in d:
64 | |             f.write((a, b))
   | |___________________________^
   |
help: Replace with `f.writelines`
   |
62 |     with open("file", "w") as f:
   -         for a, b, c in d:
   -             f.write((a, b))
63 +         f.writelines((a, b) for a, b, c in d)
64 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:69:9
   |
67 |   def _():
68 |       with open("file", "w") as f:
69 | /         for [(), [a.b], (c,)] in d:
70 | |             f.write(())
   | |_______________________^
   |
help: Replace with `f.writelines`
   |
68 |     with open("file", "w") as f:
   -         for [(), [a.b], (c,)] in d:
   -             f.write(())
69 +         f.writelines(() for [(), [a.b], (c,)] in d)
70 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:75:9
   |
73 |   def _():
74 |       with open("file", "w") as f:
75 | /         for [([([a[b]],)],), [], (c[d],)] in e:
76 | |             f.write(())
   | |_______________________^
   |
help: Replace with `f.writelines`
   |
74 |     with open("file", "w") as f:
   -         for [([([a[b]],)],), [], (c[d],)] in e:
   -             f.write(())
75 +         f.writelines(() for [([([a[b]],)],), [], (c[d],)] in e)
76 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:82:9
   |
80 |       # https://github.com/astral-sh/ruff/issues/15936
81 |       with open("file", "w") as f:
82 | /         for char in "a", "b":
83 | |             f.write(char)
   | |_________________________^
84 |
85 |   def _():
   |
help: Replace with `f.writelines`
   |
81 |     with open("file", "w") as f:
   -         for char in "a", "b":
   -             f.write(char)
82 +         f.writelines(("a", "b"))
83 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:88:9
   |
86 |       # https://github.com/astral-sh/ruff/issues/15936
87 |       with open("file", "w") as f:
88 | /         for char in "a", "b":
89 | |             f.write(f"{char}")
   | |______________________________^
90 |
91 |   def _():
   |
help: Replace with `f.writelines`
   |
87 |     with open("file", "w") as f:
   -         for char in "a", "b":
   -             f.write(f"{char}")
88 +         f.writelines(f"{char}" for char in ("a", "b"))
89 |
   |

FURB122 [*] Use of `f.write` in a for loop
  --> FURB122.py:93:9
   |
91 |   def _():
92 |       with open("file", "w") as f:
93 | /         for char in (
94 | |             "a",  # Comment
95 | |             "b"
96 | |         ):
97 | |             f.write(f"{char}")
   | |______________________________^
   |
help: Replace with `f.writelines`
   |
92 |     with open("file", "w") as f:
   -         for char in (
93 +         f.writelines(f"{char}" for char in (
94 |             "a",  # Comment
95 |             "b"
   -         ):
   -             f.write(f"{char}")
96 +         ))
97 |
   |
note: This is an unsafe fix and may change runtime behavior

FURB122 [*] Use of `f.write` in a for loop
   --> FURB122.py:183:9
    |
181 |   def _():
182 |       with Path("file.txt").open("w", encoding="utf-8") as f:
183 | /         for l in lambda: 0:
184 | |             f.write(f"[{l}]")
    | |_____________________________^
    |
help: Replace with `f.writelines`
    |
182 |     with Path("file.txt").open("w", encoding="utf-8") as f:
    -         for l in lambda: 0:
    -             f.write(f"[{l}]")
183 +         f.writelines(f"[{l}]" for l in (lambda: 0))
184 |
    |

FURB122 [*] Use of `f.write` in a for loop
   --> FURB122.py:189:9
    |
187 |   def _():
188 |       with Path("file.txt").open("w", encoding="utf-8") as f:
189 | /         for l in (1,) if True else (2,):
190 | |             f.write(f"[{l}]")
    | |_____________________________^
    |
help: Replace with `f.writelines`
    |
188 |     with Path("file.txt").open("w", encoding="utf-8") as f:
    -         for l in (1,) if True else (2,):
    -             f.write(f"[{l}]")
189 +         f.writelines(f"[{l}]" for l in ((1,) if True else (2,)))
190 |
    |

FURB122 [*] Use of `f.write` in a for loop
   --> FURB122.py:196:9
    |
194 |   def _():
195 |       with open("file", "w") as f:
196 | /         for line in lambda: 0:
197 | |             f.write(line)
    | |_________________________^
    |
help: Replace with `f.writelines`
    |
195 |     with open("file", "w") as f:
    -         for line in lambda: 0:
    -             f.write(line)
196 +         f.writelines(lambda: 0)
197 |
    |

FURB122 [*] Use of `f.write` in a for loop
   --> FURB122.py:202:9
    |
200 |   def _():
201 |       with open("file", "w") as f:
202 | /         for line in (1,) if True else (2,):
203 | |             f.write(line)
    | |_________________________^
    |
help: Replace with `f.writelines`
    |
201 |     with open("file", "w") as f:
    -         for line in (1,) if True else (2,):
    -             f.write(line)
202 +         f.writelines((1,) if True else (2,))
203 |
    |

FURB122 [*] Use of `f.write` in a for loop
   --> FURB122.py:209:9
    |
207 |   def _():
208 |       with open("file", "w") as f:
209 | /         for line in (lambda: 0):
210 | |             f.write(f"{line}")
    | |______________________________^
    |
help: Replace with `f.writelines`
    |
208 |     with open("file", "w") as f:
    -         for line in (lambda: 0):
    -             f.write(f"{line}")
209 +         f.writelines(f"{line}" for line in (lambda: 0))
210 |
    |

FURB122 [*] Use of `f.write` in a for loop
   --> FURB122.py:215:9
    |
213 |   def _():
214 |       with open("file", "w") as f:
215 | /         for line in ((1,) if True else (2,)):
216 | |             f.write(f"{line}")
    | |______________________________^
    |
help: Replace with `f.writelines`
    |
214 |     with open("file", "w") as f:
    -         for line in ((1,) if True else (2,)):
    -             f.write(f"{line}")
215 +         f.writelines(f"{line}" for line in ((1,) if True else (2,)))
    |
