Skip to content

Commit fa8ec4a

Browse files
committed
[IMP] server: clippy updates
1 parent 29253c3 commit fa8ec4a

22 files changed

+148
-178
lines changed

server/src/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn tree(a: Vec<&str>, b: Vec<&str>) -> Tree {
1414
}
1515

1616
pub fn flatten_tree(tree: &Tree) -> Vec<String> {
17-
vec![tree.0.clone(), tree.1.clone()].concat()
17+
[tree.0.clone(), tree.1.clone()].concat()
1818
}
1919

2020

server/src/core/odoo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ impl SyncOdoo {
602602
path.components().for_each(|c| {
603603
tree.0.push(c.as_os_str().to_str().unwrap().replace(".py", "").replace(".pyi", "").to_string());
604604
});
605-
if vec!["__init__", "__manifest__"].contains(&tree.0.last().unwrap().as_str()) {
605+
if ["__init__", "__manifest__"].contains(&tree.0.last().unwrap().as_str()) {
606606
tree.0.pop();
607607
}
608608
return Ok(tree);
@@ -617,7 +617,7 @@ impl SyncOdoo {
617617
path.components().for_each(|c| {
618618
tree.0.push(c.as_os_str().to_str().unwrap().replace(".py", "").to_string());
619619
});
620-
if tree.0.len() > 0 && vec!["__init__", "__manifest__"].contains(&tree.0.last().unwrap().as_str()) {
620+
if tree.0.len() > 0 && ["__init__", "__manifest__"].contains(&tree.0.last().unwrap().as_str()) {
621621
tree.0.pop();
622622
}
623623
return Ok(tree);
@@ -670,10 +670,10 @@ impl SyncOdoo {
670670
/* Consider the given 'tree' path as updated (or new) and move all symbols that were searching for it
671671
from the not_found_symbols list to the rebuild list. Return True is something should be rebuilt */
672672
pub fn search_symbols_to_rebuild(session: &mut SessionInfo, tree: &Tree) -> bool {
673-
let flat_tree = vec![tree.0.clone(), tree.1.clone()].concat();
673+
let flat_tree = [tree.0.clone(), tree.1.clone()].concat();
674674
let mut found_sym: PtrWeakHashSet<Weak<RefCell<Symbol>>> = PtrWeakHashSet::new();
675675
let mut need_rebuild = false;
676-
let mut to_add = vec![vec![], vec![], vec![], vec![]]; //list of symbols to add after the loop (borrow issue)
676+
let mut to_add = [vec![], vec![], vec![], vec![]]; //list of symbols to add after the loop (borrow issue)
677677
for s in session.sync_odoo.not_found_symbols.iter() {
678678
let mut index: i32 = 0; //i32 sa we could go in negative values
679679
while (index as usize) < s.borrow().not_found_paths().len() {

server/src/core/python_arch_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl PythonArchBuilder {
131131
&mut None).remove(0); //we don't need the vector with this call as there will be 1 result.
132132
if !import_result.found {
133133
session.sync_odoo.not_found_symbols.insert(self.file.clone());
134-
let file_tree_flattened = vec![import_result.file_tree.0.clone(), import_result.file_tree.1.clone()].concat();
134+
let file_tree_flattened = [import_result.file_tree.0.clone(), import_result.file_tree.1.clone()].concat();
135135
self.file.borrow_mut().not_found_paths_mut().push((self.current_step, file_tree_flattened));
136136
continue;
137137
}

server/src/core/python_arch_builder_hooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl PythonArchBuilderHooks {
5656
"Binary" | "Image" | "Selection" | "Reference" | "Many2one" | "Many2oneReference" | "Json" |
5757
"Properties" | "PropertiesDefinition" | "One2many" | "Many2many" | "Id" => {
5858
if sym.get_tree().0 == vec![S!("odoo"), S!("fields")] {
59-
if vec![S!("Many2one"), S!("Many2many"), S!("One2many")].contains(&sym.name()) {
59+
if [S!("Many2one"), S!("Many2many"), S!("One2many")].contains(&sym.name()) {
6060
//TODO how to do this?
6161
}
6262
// ----------- __get__ ------------

server/src/core/python_arch_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl PythonArchEval {
248248
}
249249
}
250250
} else {
251-
let mut file_tree = vec![_import_result.file_tree.0.clone(), _import_result.file_tree.1.clone()].concat();
251+
let mut file_tree = [_import_result.file_tree.0.clone(), _import_result.file_tree.1.clone()].concat();
252252
file_tree.extend(_import_result.name.split(".").map(str::to_string));
253253
self.file.borrow_mut().not_found_paths_mut().push((self.current_step, file_tree.clone()));
254254
session.sync_odoo.not_found_symbols.insert(self.file.clone());
@@ -266,7 +266,7 @@ impl PythonArchEval {
266266
}
267267

268268
} else {
269-
let mut file_tree = vec![_import_result.file_tree.0.clone(), _import_result.file_tree.1.clone()].concat();
269+
let mut file_tree = [_import_result.file_tree.0.clone(), _import_result.file_tree.1.clone()].concat();
270270
file_tree.extend(_import_result.name.split(".").map(str::to_string));
271271
if BUILT_IN_LIBS.contains(&file_tree[0].as_str()) {
272272
continue;

server/src/core/python_arch_eval_hooks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static arch_eval_file_hooks: Lazy<Vec<PythonArchEvalFileHook>> = Lazy::new(|| {v
6363
let values: Vec<ruff_python_ast::Expr> = Vec::new();
6464
let mut id = symbol.borrow_mut();
6565
let range = id.range().clone();
66-
id.set_evaluations(vec![Evaluation::new_list(odoo, values, range.clone())]);
66+
id.set_evaluations(vec![Evaluation::new_list(odoo, values, range)]);
6767
}},
6868
/*PythonArchEvalFileHook { file_tree: vec![S!("odoo"), S!("models")],
6969
content_tree: vec![S!("BaseModel"), S!("search_count")],
@@ -436,7 +436,7 @@ impl PythonArchEvalHooks {
436436
f.add_model_dependencies(model);
437437
}
438438
let symbols = model.clone().borrow().get_main_symbols(session, from_module.clone(), &mut None);
439-
if symbols.len() > 0 {
439+
if !symbols.is_empty() {
440440
for s in symbols.iter() {
441441
if from_module.is_none() || ModuleSymbol::is_in_deps(session, &from_module.as_ref().unwrap(),&s.borrow().find_module().unwrap().borrow().as_module_package().dir_name, &mut None) {
442442
return EvaluationSymbolWeak::new(Rc::downgrade(s), Some(true), false);

server/src/core/python_odoo_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl PythonOdooBuilder {
3636
return;
3737
}
3838
let mut path = symbol.paths()[0].clone();
39-
if vec![SymType::NAMESPACE, SymType::ROOT, SymType::COMPILED].contains(&symbol.typ()) {
39+
if [SymType::NAMESPACE, SymType::ROOT, SymType::COMPILED].contains(&symbol.typ()) {
4040
return;
4141
} else if matches!(symbol.typ(), SymType::PACKAGE(_)) {
4242
path = PathBuf::from(path).join("__init__").with_extension(S!("py") + symbol.as_package().i_ext().as_str()).sanitize();

server/src/core/python_utils.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn _link_tuples(targets: Vec<Expr>, values: Vec<Expr>) -> Vec<Assign> {
8181
res
8282
}
8383

84-
pub fn unpack_assign(targets: &Vec<Expr>, annotation: Option<&Box<Expr>>, value: Option<&Box<Expr>>) -> Vec<Assign> {
84+
pub fn unpack_assign(targets: &Vec<Expr>, annotation: Option<&Expr>, value: Option<&Expr>) -> Vec<Assign> {
8585
//Given the target, the annotation and the values, return a list of tuples (variable: ExprName, annotation, value)
8686
//for each variable, associating annotation and value for the right variable
8787
// Ex: for "a = b = 1", return [("a", None, 1), ("b", , None, 1)]
@@ -102,21 +102,15 @@ pub fn unpack_assign(targets: &Vec<Expr>, annotation: Option<&Box<Expr>>, value:
102102
Some(value) => {
103103
res.push(Assign {
104104
target: expr.clone(),
105-
annotation: match annotation {
106-
Some(annotation) => Some(*annotation.clone()),
107-
None => None,
108-
},
109-
value: Some(*value.clone()),
105+
annotation: annotation.cloned(),
106+
value: Some(value.clone()),
110107
index: None,
111108
});
112109
},
113110
None => {
114111
res.push(Assign {
115112
target: expr.clone(),
116-
annotation: match annotation {
117-
Some(annotation) => Some(*annotation.clone()),
118-
None => None,
119-
},
113+
annotation: annotation.cloned(),
120114
value: None,
121115
index: None,
122116
});
@@ -142,7 +136,7 @@ pub fn unpack_assign(targets: &Vec<Expr>, annotation: Option<&Box<Expr>>, value:
142136
res.push(Assign {
143137
target: tar.clone(),
144138
annotation: None,
145-
value: Some(*value.clone()),
139+
value: Some(value.clone()),
146140
index: Some(index),
147141
});
148142
}
@@ -169,7 +163,7 @@ pub fn unpack_assign(targets: &Vec<Expr>, annotation: Option<&Box<Expr>>, value:
169163
res.push(Assign {
170164
target: tar.clone(),
171165
annotation: None,
172-
value: Some(*value.clone()),
166+
value: Some(value.clone()),
173167
index: Some(index),
174168
});
175169
}

server/src/core/python_validator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl PythonValidator {
246246
if import_result.found && self.current_module.is_some() {
247247
let module = import_result.symbol.borrow().find_module();
248248
if let Some(module) = module {
249-
if !ModuleSymbol::is_in_deps(session, &self.current_module.as_ref().unwrap(), &module.borrow().as_module_package().dir_name, &mut None) && !self.safe_imports.last().unwrap() {
249+
if !ModuleSymbol::is_in_deps(session, self.current_module.as_ref().unwrap(), &module.borrow().as_module_package().dir_name, &mut None) && !self.safe_imports.last().unwrap() {
250250
self.diagnostics.push(Diagnostic::new(
251251
Range::new(Position::new(import_result.range.start().to_u32(), 0), Position::new(import_result.range.end().to_u32(), 0)),
252252
Some(DiagnosticSeverity::ERROR),
@@ -327,13 +327,13 @@ impl PythonValidator {
327327
if let Some(main_sym_module) = main_sym_module {
328328
let module_name = main_sym_module.borrow().as_module_package().dir_name.clone();
329329
main_modules.push(module_name.clone());
330-
if ModuleSymbol::is_in_deps(session, &from, &module_name, &mut None) {
330+
if ModuleSymbol::is_in_deps(session, from, &module_name, &mut None) {
331331
found_one = true;
332332
}
333333
}
334334
}
335335
if !found_one {
336-
if main_modules.len() > 0 {
336+
if !main_modules.is_empty() {
337337
self.diagnostics.push(Diagnostic::new(
338338
Range::new(Position::new(range.start().to_u32(), 0), Position::new(range.end().to_u32(), 0)),
339339
Some(DiagnosticSeverity::ERROR),
@@ -372,7 +372,7 @@ impl PythonValidator {
372372
}
373373

374374
fn validate_expr(&mut self, session: &mut SessionInfo, expr: &Expr, max_infer: &TextSize) {
375-
let (eval, diags) = Evaluation::eval_from_ast(session, &expr, self.sym_stack.last().unwrap().clone(), &max_infer);
375+
let (eval, diags) = Evaluation::eval_from_ast(session, expr, self.sym_stack.last().unwrap().clone(), max_infer);
376376
self.diagnostics.extend(diags);
377377
}
378378
}

server/src/core/symbols/class_symbol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ impl ClassSymbol {
6969
return false;
7070
}
7171
checked.as_mut().unwrap().insert(b.clone());
72-
if b.borrow().as_class_sym().inherits(&base, checked) {
72+
if b.borrow().as_class_sym().inherits(base, checked) {
7373
return true;
7474
}
7575
}
7676
false
7777
}
7878

7979
pub fn add_symbol(&mut self, content: &Rc<RefCell<Symbol>>, section: u32) {
80-
let sections = self.symbols.entry(content.borrow().name().clone()).or_insert_with(|| HashMap::new());
81-
let section_vec = sections.entry(section).or_insert_with(|| vec![]);
80+
let sections = self.symbols.entry(content.borrow().name().clone()).or_insert(HashMap::new());
81+
let section_vec = sections.entry(section).or_insert(vec![]);
8282
section_vec.push(content.clone());
8383
}
8484

0 commit comments

Comments
 (0)