Skip to content

Commit bb878a3

Browse files
committed
PyFloat to use extend_class for __new__ and __doc__
1 parent 08b716f commit bb878a3

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

vm/src/obj/objfloat.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use num_bigint::{BigInt, ToBigInt};
1111
use num_rational::Ratio;
1212
use num_traits::ToPrimitive;
1313

14+
/// Convert a string or number to a floating point number, if possible.
1415
#[pyclass(name = "float")]
1516
#[derive(Debug, Copy, Clone, PartialEq)]
1617
pub struct PyFloat {
@@ -222,7 +223,8 @@ impl PyFloat {
222223
)
223224
}
224225

225-
fn new_float(cls: PyClassRef, arg: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyFloatRef> {
226+
#[pymethod(name = "__new__")]
227+
fn float_new(cls: PyClassRef, arg: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyFloatRef> {
226228
let value = if objtype::isinstance(&arg, &vm.ctx.float_type()) {
227229
get_value(&arg)
228230
} else if objtype::isinstance(&arg, &vm.ctx.int_type()) {
@@ -408,9 +410,4 @@ pub fn make_float(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<f64> {
408410
#[rustfmt::skip] // to avoid line splitting
409411
pub fn init(context: &PyContext) {
410412
PyFloat::extend_class(context, &context.float_type);
411-
let float_doc = "Convert a string or number to a floating point number, if possible.";
412-
extend_class!(context, &context.float_type, {
413-
"__new__" => context.new_rustfunc(PyFloat::new_float),
414-
"__doc__" => context.new_str(float_doc.to_string()),
415-
});
416413
}

0 commit comments

Comments
 (0)