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

This commit is contained in:
Gyubong authored and GitHub committed 2022-08-01 01:52:15 +09:00
1 parent 0341e72d94
commit e8ed8aab9f
2 files changed
+6

No files matched your search

+2
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
+4
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 {