File tree 5 files changed +14
-15
lines changed
5 files changed +14
-15
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,7 @@ pub fn read_file(file_path: &str) -> PyResult<String> {
20
20
Ok ( content) => Ok ( content) ,
21
21
Err ( e) => match e. kind ( ) {
22
22
ErrorKind :: NotFound => Err ( PyFileNotFoundError :: new_err ( format ! (
23
- "File not found: '{}'" ,
24
- file_path
23
+ "File not found: '{file_path}'" ,
25
24
) ) ) ,
26
25
ErrorKind :: InvalidData => {
27
26
let file = File :: open ( path) . unwrap ( ) ;
@@ -32,7 +31,7 @@ pub fn read_file(file_path: &str) -> PyResult<String> {
32
31
. unwrap_or_else ( || guess_encoding ( & buffer) ) ;
33
32
read_with_encoding ( & buffer, encoding)
34
33
}
35
- _ => Err ( PyIOError :: new_err ( format ! ( "An error occurred: '{}'" , e ) ) ) ,
34
+ _ => Err ( PyIOError :: new_err ( format ! ( "An error occurred: '{e }'" ) ) ) ,
36
35
} ,
37
36
}
38
37
}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ fn _extract_code_from_notebook_cells(cells: &[serde_json::Value]) -> String {
63
63
let code_lines: Vec < String > = cells
64
64
. iter ( )
65
65
. filter ( |cell| cell[ "cell_type" ] == "code" )
66
- . flat_map ( |cell| cell[ "source" ] . as_array ( ) )
66
+ . filter_map ( |cell| cell[ "source" ] . as_array ( ) )
67
67
. flatten ( )
68
68
. filter_map ( |line| line. as_str ( ) )
69
69
. map ( str:: to_owned)
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ pub fn get_ast_from_file_content(file_content: &str) -> PyResult<Mod> {
29
29
}
30
30
31
31
/// Iterates through an AST to identify and collect import statements, and returns them together with their
32
- /// respective TextRange for each occurrence.
32
+ /// respective ` TextRange` for each occurrence.
33
33
pub fn extract_imports_from_ast ( ast : Mod ) -> HashMap < String , Vec < TextRange > > {
34
34
let mut visitor = ImportVisitor :: new ( ) ;
35
35
@@ -62,7 +62,7 @@ pub fn convert_imports_with_textranges_to_location_objects(
62
62
. column
63
63
. get ( ) ;
64
64
Location {
65
- file : file_path. to_string ( ) ,
65
+ file : file_path. to_owned ( ) ,
66
66
line : Some ( start_line) ,
67
67
column : Some ( start_col) ,
68
68
}
@@ -73,7 +73,7 @@ pub fn convert_imports_with_textranges_to_location_objects(
73
73
imports_with_locations
74
74
}
75
75
76
- /// Transforms a Rust HashMap containing import data into a Python dictionary suitable for Python-side consumption.
76
+ /// Transforms a Rust ` HashMap` containing import data into a Python dictionary suitable for Python-side consumption.
77
77
pub fn convert_to_python_dict (
78
78
py : Python < ' _ > ,
79
79
imports_with_locations : FileToImportsMap ,
Original file line number Diff line number Diff line change @@ -14,14 +14,14 @@ pub struct Location {
14
14
#[ pymethods]
15
15
impl Location {
16
16
#[ new]
17
- pub fn new ( file : String , line : Option < usize > , column : Option < usize > ) -> Self {
18
- Location { file, line, column }
17
+ fn new ( file : String , line : Option < usize > , column : Option < usize > ) -> Self {
18
+ Self { file, line, column }
19
19
}
20
20
21
- fn __repr__ ( & self ) -> PyResult < String > {
22
- Ok ( format ! (
21
+ fn __repr__ ( & self ) -> String {
22
+ format ! (
23
23
"Location(file='{}', line={:?}, column={:?})" ,
24
24
self . file, self . line, self . column
25
- ) )
25
+ )
26
26
}
27
27
}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pub struct ImportVisitor {
10
10
11
11
impl ImportVisitor {
12
12
pub fn new ( ) -> Self {
13
- ImportVisitor {
13
+ Self {
14
14
imports : HashMap :: new ( ) ,
15
15
}
16
16
}
@@ -49,11 +49,11 @@ impl<'a> Visitor<'a> for ImportVisitor {
49
49
}
50
50
51
51
/// Extracts the top-level module name from a potentially nested module path.
52
- /// e.g. when a module_name is `foo.bar`, this returns `foo`.
52
+ /// e.g. when a ` module_name` is `foo.bar`, this returns `foo`.
53
53
fn get_top_level_module_name ( module_name : & str ) -> String {
54
54
module_name
55
55
. split ( '.' )
56
56
. next ( )
57
57
. unwrap_or ( module_name)
58
- . to_string ( )
58
+ . to_owned ( )
59
59
}
You can’t perform that action at this time.
0 commit comments