mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
style: rustfmt
This commit is contained in:
@@ -135,8 +135,12 @@ impl ExceptionZoo {
|
||||
|
||||
let overflow_error =
|
||||
create_type("OverflowError", &type_type, &arithmetic_error, &dict_type);
|
||||
let zero_division_error =
|
||||
create_type("ZeroDivisionError", &type_type, &arithmetic_error, &dict_type);
|
||||
let zero_division_error = create_type(
|
||||
"ZeroDivisionError",
|
||||
&type_type,
|
||||
&arithmetic_error,
|
||||
&dict_type,
|
||||
);
|
||||
|
||||
let module_not_found_error =
|
||||
create_type("ModuleNotFoundError", &type_type, &import_error, &dict_type);
|
||||
|
||||
@@ -371,11 +371,13 @@ fn int_truediv(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
required = [(i, Some(vm.ctx.int_type())), (i2, None)]
|
||||
);
|
||||
|
||||
let v1 = get_value(i).to_f64()
|
||||
let v1 = get_value(i)
|
||||
.to_f64()
|
||||
.ok_or_else(|| vm.new_overflow_error("int too large to convert to float".to_string()))?;
|
||||
|
||||
let v2 = if objtype::isinstance(i2, &vm.ctx.int_type()) {
|
||||
get_value(i2).to_f64()
|
||||
get_value(i2)
|
||||
.to_f64()
|
||||
.ok_or_else(|| vm.new_overflow_error("int too large to convert to float".to_string()))?
|
||||
} else if objtype::isinstance(i2, &vm.ctx.float_type()) {
|
||||
objfloat::get_value(i2)
|
||||
@@ -386,9 +388,7 @@ fn int_truediv(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
|
||||
if v2 == 0.0 {
|
||||
Err(vm.new_zero_division_error("integer division by zero".to_string()))
|
||||
} else {
|
||||
Ok(vm
|
||||
.ctx
|
||||
.new_float(v1 / v2))
|
||||
Ok(vm.ctx.new_float(v1 / v2))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::super::pyobject::{
|
||||
use super::super::vm::VirtualMachine;
|
||||
use super::objint;
|
||||
use super::objtype;
|
||||
use num_bigint::{BigInt, ToBigInt, Sign};
|
||||
use num_bigint::{BigInt, Sign, ToBigInt};
|
||||
use num_traits::{One, Signed, ToPrimitive, Zero};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -20,10 +20,14 @@ impl RangeType {
|
||||
#[inline]
|
||||
pub fn try_len(&self) -> Option<usize> {
|
||||
match self.step.sign() {
|
||||
Sign::Plus if self.start < self.end =>
|
||||
((&self.end - &self.start - 1usize) / &self.step).to_usize().map(|sz| sz + 1),
|
||||
Sign::Minus if self.start > self.end =>
|
||||
((&self.start - &self.end - 1usize) / (-&self.step)).to_usize().map(|sz| sz + 1),
|
||||
Sign::Plus if self.start < self.end => ((&self.end - &self.start - 1usize)
|
||||
/ &self.step)
|
||||
.to_usize()
|
||||
.map(|sz| sz + 1),
|
||||
Sign::Minus if self.start > self.end => ((&self.start - &self.end - 1usize)
|
||||
/ (-&self.step))
|
||||
.to_usize()
|
||||
.map(|sz| sz + 1),
|
||||
_ => Some(0),
|
||||
}
|
||||
}
|
||||
@@ -56,7 +60,7 @@ impl RangeType {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn repr(&self) -> String {
|
||||
if self.step == BigInt::one() {
|
||||
|
||||
Reference in New Issue
Block a user