Skip to content

Commit 5d46978

Browse files
author
Boxiang Sun
committed
use CPython's behaviour in floatNew
1 parent 59a7a2f commit 5d46978

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/runtime/float.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -868,27 +868,15 @@ template <ExceptionStyle S> static BoxedFloat* _floatNew(Box* a) noexcept(S == C
868868

869869
return res;
870870
} else {
871-
static BoxedString* float_str = internStringImmortal("__float__");
872-
Box* r = callattrInternal<S, NOT_REWRITABLE>(a, float_str, CLASS_ONLY, NULL, ArgPassSpec(0), NULL, NULL, NULL,
873-
NULL, NULL);
874-
871+
Box* r = PyNumber_Float(a);
875872
if (!r) {
876873
if (S == CAPI) {
877-
if (!PyErr_Occurred())
878-
PyErr_SetString(PyExc_TypeError, "float() argument must be a string or a number");
879874
return NULL;
880875
} else {
881-
raiseExcHelper(TypeError, "float() argument must be a string or a number");
876+
throwCAPIException();
882877
}
883878
}
884879

885-
if (!PyFloat_Check(r)) {
886-
if (S == CAPI) {
887-
PyErr_Format(TypeError, "__float__ returned non-float (type %s)", r->cls->tp_name);
888-
return NULL;
889-
} else
890-
raiseExcHelper(TypeError, "__float__ returned non-float (type %s)", r->cls->tp_name);
891-
}
892880
return static_cast<BoxedFloat*>(r);
893881
}
894882
}

0 commit comments

Comments
 (0)