mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Fix PyFloat::py_new always returning new float object issue (#3979)
This commit is contained in:
@@ -441,6 +441,8 @@ assert float('inf').hex() == 'inf'
|
||||
assert float('-inf').hex() == '-inf'
|
||||
assert float('nan').hex() == 'nan'
|
||||
|
||||
assert float(math.nan) is float(math.nan)
|
||||
|
||||
# Test float exponent:
|
||||
assert 1 if 1else 0 == 1
|
||||
|
||||
|
||||
@@ -142,6 +142,10 @@ impl Constructor for PyFloat {
|
||||
let float_val = match arg {
|
||||
OptionalArg::Missing => 0.0,
|
||||
OptionalArg::Present(val) => {
|
||||
if cls.is(vm.ctx.types.float_type) && val.class().is(vm.ctx.types.float_type) {
|
||||
return Ok(val);
|
||||
}
|
||||
|
||||
if let Some(f) = val.try_float_opt(vm)? {
|
||||
f.value
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user