Skip to content

Commit b0cbb23

Browse files
committed
Fixed the 'collapsible_if' clippy warnings
Relevant clippy warning: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
1 parent 7941480 commit b0cbb23

File tree

4 files changed

+34
-46
lines changed

4 files changed

+34
-46
lines changed

vm/src/obj/objobject.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,19 @@ fn object_getattribute(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
151151
Ok(obj_attr)
152152
} else if let Some(attr) = cls.get_attr(&name) {
153153
vm.call_get_descriptor(attr, obj.clone())
154+
} else if let Some(getter) = cls.get_attr("__getattr__") {
155+
vm.invoke(
156+
getter,
157+
PyFuncArgs {
158+
args: vec![cls, name_str.clone()],
159+
kwargs: vec![],
160+
},
161+
)
154162
} else {
155-
if let Some(getter) = cls.get_attr("__getattr__") {
156-
vm.invoke(
157-
getter,
158-
PyFuncArgs {
159-
args: vec![cls, name_str.clone()],
160-
kwargs: vec![],
161-
},
162-
)
163-
} else {
164-
let attribute_error = vm.context().exceptions.attribute_error.clone();
165-
Err(vm.new_exception(
166-
attribute_error,
167-
format!("{} has no attribute '{}'", obj.borrow(), name),
168-
))
169-
}
163+
let attribute_error = vm.context().exceptions.attribute_error.clone();
164+
Err(vm.new_exception(
165+
attribute_error,
166+
format!("{} has no attribute '{}'", obj.borrow(), name),
167+
))
170168
}
171169
}

vm/src/obj/objstr.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,8 @@ fn str_isidentifier(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
450450
&& !value.chars().nth(0).unwrap().is_digit(10)
451451
{
452452
for c in value.chars() {
453-
if c != "_".chars().nth(0).unwrap() {
454-
if !c.is_digit(10) {
455-
if !c.is_alphabetic() {
456-
is_identifier = false;
457-
}
458-
}
453+
if c != "_".chars().nth(0).unwrap() && !c.is_digit(10) && !c.is_alphabetic() {
454+
is_identifier = false;
459455
}
460456
}
461457
} else {

vm/src/obj/objtype.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,20 @@ pub fn type_getattribute(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult
192192
Ok(cls_attr)
193193
} else if let Some(attr) = mcl.get_attr(&name) {
194194
vm.call_get_descriptor(attr, cls.clone())
195+
} else if let Some(getter) = cls.get_attr("__getattr__") {
196+
vm.invoke(
197+
getter,
198+
PyFuncArgs {
199+
args: vec![mcl, name_str.clone()],
200+
kwargs: vec![],
201+
},
202+
)
195203
} else {
196-
if let Some(getter) = cls.get_attr("__getattr__") {
197-
vm.invoke(
198-
getter,
199-
PyFuncArgs {
200-
args: vec![mcl, name_str.clone()],
201-
kwargs: vec![],
202-
},
203-
)
204-
} else {
205-
let attribute_error = vm.context().exceptions.attribute_error.clone();
206-
Err(vm.new_exception(
207-
attribute_error,
208-
format!("{} has no attribute '{}'", cls.borrow(), name),
209-
))
210-
}
204+
let attribute_error = vm.context().exceptions.attribute_error.clone();
205+
Err(vm.new_exception(
206+
attribute_error,
207+
format!("{} has no attribute '{}'", cls.borrow(), name),
208+
))
211209
}
212210
}
213211

vm/src/stdlib/math.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,10 @@ fn math_gamma(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
177177

178178
if x.is_finite() {
179179
Ok(vm.ctx.new_float(gamma(x)))
180+
} else if x.is_nan() || x.is_sign_positive() {
181+
Ok(vm.ctx.new_float(x))
180182
} else {
181-
if x.is_nan() || x.is_sign_positive() {
182-
Ok(vm.ctx.new_float(x))
183-
} else {
184-
Ok(vm.ctx.new_float(std::f64::NAN))
185-
}
183+
Ok(vm.ctx.new_float(std::f64::NAN))
186184
}
187185
}
188186

@@ -192,12 +190,10 @@ fn math_lgamma(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
192190

193191
if x.is_finite() {
194192
Ok(vm.ctx.new_float(ln_gamma(x)))
193+
} else if x.is_nan() {
194+
Ok(vm.ctx.new_float(x))
195195
} else {
196-
if x.is_nan() {
197-
Ok(vm.ctx.new_float(x))
198-
} else {
199-
Ok(vm.ctx.new_float(std::f64::INFINITY))
200-
}
196+
Ok(vm.ctx.new_float(std::f64::INFINITY))
201197
}
202198
}
203199

0 commit comments

Comments
 (0)