11-- -
22source : crates / ruff_linter / src / rules / refurb / mod .rs
33-- -
4- FURB101 ` open` and ` read` should be replaced by ` Path("file.txt").read_text()`
4+ FURB101 [ * ] ` open` and ` read` should be replaced by ` Path("file.txt").read_text()`
55 -- > FURB101 .py :12 :6
66 |
7711 | # FURB101
@@ -10,8 +10,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text()`
101013 | x = f .read ()
1111 |
1212help : Replace with ` Path("file.txt").read_text()`
13+ 1 + import pathlib
14+ 2 | def foo ():
15+ 3 | ...
16+ 4 |
17+ --------------------------------------------------------------------------------
18+ 10 | # Errors .
19+ 11 |
20+ 12 | # FURB101
21+ - with open (" file.txt" ) as f :
22+ - x = f .read ()
23+ 13 + x = pathlib .Path (" file.txt" ).read_text ()
24+ 14 |
25+ 15 | # FURB101
26+ 16 | with open (" file.txt" , " rb" ) as f :
1327
14- FURB101 ` open` and ` read` should be replaced by ` Path("file.txt").read_bytes()`
28+ FURB101 [ * ] ` open` and ` read` should be replaced by ` Path("file.txt").read_bytes()`
1529 -- > FURB101 .py :16 :6
1630 |
173115 | # FURB101
@@ -20,8 +34,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
203417 | x = f .read ()
2135 |
2236help : Replace with ` Path("file.txt").read_bytes()`
37+ 1 + import pathlib
38+ 2 | def foo ():
39+ 3 | ...
40+ 4 |
41+ --------------------------------------------------------------------------------
42+ 14 | x = f .read ()
43+ 15 |
44+ 16 | # FURB101
45+ - with open (" file.txt" , " rb" ) as f :
46+ - x = f .read ()
47+ 17 + x = pathlib .Path (" file.txt" ).read_bytes ()
48+ 18 |
49+ 19 | # FURB101
50+ 20 | with open (" file.txt" , mode = " rb" ) as f :
2351
24- FURB101 ` open` and ` read` should be replaced by ` Path("file.txt").read_bytes()`
52+ FURB101 [ * ] ` open` and ` read` should be replaced by ` Path("file.txt").read_bytes()`
2553 -- > FURB101 .py :20 :6
2654 |
275519 | # FURB101
@@ -30,8 +58,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_bytes()`
305821 | x = f .read ()
3159 |
3260help : Replace with ` Path("file.txt").read_bytes()`
61+ 1 + import pathlib
62+ 2 | def foo ():
63+ 3 | ...
64+ 4 |
65+ --------------------------------------------------------------------------------
66+ 18 | x = f .read ()
67+ 19 |
68+ 20 | # FURB101
69+ - with open (" file.txt" , mode = " rb" ) as f :
70+ - x = f .read ()
71+ 21 + x = pathlib .Path (" file.txt" ).read_bytes ()
72+ 22 |
73+ 23 | # FURB101
74+ 24 | with open (" file.txt" , encoding = " utf8" ) as f :
3375
34- FURB101 ` open` and ` read` should be replaced by ` Path("file.txt").read_text(encoding="utf8")`
76+ FURB101 [ * ] ` open` and ` read` should be replaced by ` Path("file.txt").read_text(encoding="utf8")`
3577 -- > FURB101 .py :24 :6
3678 |
377923 | # FURB101
@@ -40,8 +82,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text(enco
408225 | x = f .read ()
4183 |
4284help : Replace with ` Path("file.txt").read_text(encoding="utf8")`
85+ 1 + import pathlib
86+ 2 | def foo ():
87+ 3 | ...
88+ 4 |
89+ --------------------------------------------------------------------------------
90+ 22 | x = f .read ()
91+ 23 |
92+ 24 | # FURB101
93+ - with open (" file.txt" , encoding = " utf8" ) as f :
94+ - x = f .read ()
95+ 25 + x = pathlib .Path (" file.txt" ).read_text (encoding = " utf8" )
96+ 26 |
97+ 27 | # FURB101
98+ 28 | with open (" file.txt" , errors = " ignore" ) as f :
4399
44- FURB101 ` open` and ` read` should be replaced by ` Path("file.txt").read_text(errors="ignore")`
100+ FURB101 [ * ] ` open` and ` read` should be replaced by ` Path("file.txt").read_text(errors="ignore")`
45101 -- > FURB101 .py :28 :6
46102 |
4710327 | # FURB101
@@ -50,8 +106,22 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text(erro
5010629 | x = f .read ()
51107 |
52108help : Replace with ` Path("file.txt").read_text(errors="ignore")`
109+ 1 + import pathlib
110+ 2 | def foo ():
111+ 3 | ...
112+ 4 |
113+ --------------------------------------------------------------------------------
114+ 26 | x = f .read ()
115+ 27 |
116+ 28 | # FURB101
117+ - with open (" file.txt" , errors = " ignore" ) as f :
118+ - x = f .read ()
119+ 29 + x = pathlib .Path (" file.txt" ).read_text (errors = " ignore" )
120+ 30 |
121+ 31 | # FURB101
122+ 32 | with open (" file.txt" , mode = " r" ) as f : # noqa : FURB120
53123
54- FURB101 ` open` and ` read` should be replaced by ` Path("file.txt").read_text()`
124+ FURB101 [ * ] ` open` and ` read` should be replaced by ` Path("file.txt").read_text()`
55125 -- > FURB101 .py :32 :6
56126 |
5712731 | # FURB101
@@ -60,6 +130,21 @@ FURB101 `open` and `read` should be replaced by `Path("file.txt").read_text()`
6013033 | x = f .read ()
61131 |
62132help : Replace with ` Path("file.txt").read_text()`
133+ 1 + import pathlib
134+ 2 | def foo ():
135+ 3 | ...
136+ 4 |
137+ --------------------------------------------------------------------------------
138+ 30 | x = f .read ()
139+ 31 |
140+ 32 | # FURB101
141+ - with open (" file.txt" , mode = " r" ) as f : # noqa : FURB120
142+ - x = f .read ()
143+ 33 + x = pathlib .Path (" file.txt" ).read_text ()
144+ 34 |
145+ 35 | # FURB101
146+ 36 | with open (foo (), " rb" ) as f :
147+ note : This is an unsafe fix and may change runtime behavior
63148
64149FURB101 ` open` and ` read` should be replaced by ` Path(foo()).read_bytes()`
65150 -- > FURB101 .py :36 :6
0 commit comments