mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
PyFloat to use extend_class for __new__ and __doc__
This commit is contained in:
1 parent
08b716f694
commit
bb878a3402
1 file changed
+3
-6
@@ -11,6 +11,7 @@ use num_bigint::{BigInt, ToBigInt};
|
||||
use num_rational::Ratio;
|
||||
use num_traits::ToPrimitive;
|
||||
|
||||
/// Convert a string or number to a floating point number, if possible.
|
||||
#[pyclass(name = "float")]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub struct PyFloat {
|
||||
@@ -222,7 +223,8 @@ impl PyFloat {
|
||||
)
|
||||
}
|
||||
|
||||
fn new_float(cls: PyClassRef, arg: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyFloatRef> {
|
||||
#[pymethod(name = "__new__")]
|
||||
fn float_new(cls: PyClassRef, arg: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyFloatRef> {
|
||||
let value = if objtype::isinstance(&arg, &vm.ctx.float_type()) {
|
||||
get_value(&arg)
|
||||
} else if objtype::isinstance(&arg, &vm.ctx.int_type()) {
|
||||
@@ -408,9 +410,4 @@ pub fn make_float(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<f64> {
|
||||
#[rustfmt::skip] // to avoid line splitting
|
||||
pub fn init(context: &PyContext) {
|
||||
PyFloat::extend_class(context, &context.float_type);
|
||||
let float_doc = "Convert a string or number to a floating point number, if possible.";
|
||||
extend_class!(context, &context.float_type, {
|
||||
"__new__" => context.new_rustfunc(PyFloat::new_float),
|
||||
"__doc__" => context.new_str(float_doc.to_string()),
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user