@@ -25,11 +25,11 @@ pub struct DeclFileGenerator {
25
25
}
26
26
27
27
impl DeclFileGenerator {
28
- pub fn new ( path : & NormalizedPathBuf , status : CheckStatus ) -> Self {
28
+ pub fn new ( path : & NormalizedPathBuf , status : CheckStatus ) -> std :: io :: Result < Self > {
29
29
let ( timestamp, hash) = {
30
- let metadata = std:: fs:: metadata ( path) . unwrap ( ) ;
30
+ let metadata = std:: fs:: metadata ( path) ? ;
31
31
let dummy_hash = metadata. len ( ) ;
32
- ( metadata. modified ( ) . unwrap ( ) , dummy_hash)
32
+ ( metadata. modified ( ) ? , dummy_hash)
33
33
} ;
34
34
let status = PylyzerStatus {
35
35
status,
@@ -38,16 +38,16 @@ impl DeclFileGenerator {
38
38
hash,
39
39
} ;
40
40
let code = format ! ( "{status}\n " ) ;
41
- Self {
41
+ Ok ( Self {
42
42
filename : path
43
43
. file_name ( )
44
- . unwrap ( )
44
+ . unwrap_or_default ( )
45
45
. to_string_lossy ( )
46
46
. replace ( ".py" , ".d.er" ) ,
47
47
namespace : "" . to_string ( ) ,
48
48
imported : Set :: new ( ) ,
49
49
code,
50
- }
50
+ } )
51
51
}
52
52
53
53
pub fn gen_decl_er ( mut self , hir : & HIR ) -> DeclFile {
@@ -209,31 +209,29 @@ impl DeclFileGenerator {
209
209
}
210
210
}
211
211
212
- fn dump_decl_er ( path : & NormalizedPathBuf , hir : & HIR , status : CheckStatus ) {
213
- let decl_gen = DeclFileGenerator :: new ( path, status) ;
212
+ fn dump_decl_er ( path : & NormalizedPathBuf , hir : & HIR , status : CheckStatus ) -> std :: io :: Result < ( ) > {
213
+ let decl_gen = DeclFileGenerator :: new ( path, status) ? ;
214
214
let file = decl_gen. gen_decl_er ( hir) ;
215
215
let Some ( dir) = path. parent ( ) . and_then ( |p| p. canonicalize ( ) . ok ( ) ) else {
216
- return ;
216
+ return Ok ( ( ) ) ;
217
217
} ;
218
218
let cache_dir = dir. join ( "__pycache__" ) ;
219
219
if !cache_dir. exists ( ) {
220
220
let _ = create_dir_all ( & cache_dir) ;
221
221
}
222
222
let path = cache_dir. join ( file. filename ) ;
223
223
if !path. exists ( ) {
224
- let _f = File :: create ( & path) ;
224
+ File :: create ( & path) ? ;
225
225
}
226
- let Ok ( f) = File :: options ( ) . write ( true ) . open ( path) else {
227
- return ;
228
- } ;
226
+ let f = File :: options ( ) . write ( true ) . open ( path) ?;
229
227
let mut f = BufWriter :: new ( f) ;
230
- let _ = f. write_all ( file. code . as_bytes ( ) ) ;
228
+ f. write_all ( file. code . as_bytes ( ) )
231
229
}
232
230
233
231
pub fn dump_decl_package ( modules : & SharedModuleCache ) {
234
232
for ( path, module) in modules. raw_iter ( ) {
235
233
if let Some ( hir) = module. hir . as_ref ( ) {
236
- dump_decl_er ( path, hir, module. status ) ;
234
+ let _ = dump_decl_er ( path, hir, module. status ) ;
237
235
}
238
236
}
239
237
}
0 commit comments