Fix PyFloat::py_new always returning new float object issue (#3979)

This commit is contained in:
Gyubong
2022-08-01 01:52:15 +09:00
committed by GitHub
parent 0341e72d94
commit e8ed8aab9f
2 changed files with 6 additions and 0 deletions

View File

@@ -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

View File

@@ -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 {