Commit f8fa6b3b authored by Marius Wachtler's avatar Marius Wachtler

Fix long(None)

parent e9152be5
......@@ -951,11 +951,10 @@ template <ExceptionStyle S> static BoxedFloat* _floatNew(Box* a) noexcept(S == C
if (!r) {
if (S == CAPI) {
if (!PyErr_Occurred())
PyErr_Format(TypeError, "float() argument must be a string or a number, not '%s'\n",
getTypeName(a));
PyErr_SetString(PyExc_TypeError, "float() argument must be a string or a number");
return NULL;
} else {
raiseExcHelper(TypeError, "float() argument must be a string or a number, not '%s'\n", getTypeName(a));
raiseExcHelper(TypeError, "float() argument must be a string or a number");
}
}
......
......@@ -666,7 +666,7 @@ template <ExceptionStyle S> Box* _longNew(Box* val, Box* _base) noexcept(S == CA
return NULL;
}
if (val == None) {
if (val == NULL) {
PyErr_SetString(PyExc_TypeError, "long() missing string argument");
return NULL;
}
......@@ -679,7 +679,7 @@ template <ExceptionStyle S> Box* _longNew(Box* val, Box* _base) noexcept(S == CA
if (!PyInt_Check(_base))
raiseExcHelper(TypeError, "integer argument expected, got %s", getTypeName(_base));
if (val == None)
if (val == NULL)
raiseExcHelper(TypeError, "long() missing string argument");
if (!PyString_Check(val) && !PyUnicode_Check(val))
......@@ -687,7 +687,7 @@ template <ExceptionStyle S> Box* _longNew(Box* val, Box* _base) noexcept(S == CA
}
base = static_cast<BoxedInt*>(_base)->n;
} else {
if (val == None)
if (val == NULL)
return PyLong_FromLong(0L);
Box* r = PyNumber_Long(val);
......@@ -1647,7 +1647,7 @@ void setupLong() {
auto long_new = FunctionMetadata::create((void*)longNew<CXX>, UNKNOWN, 3, false, false,
ParamNames({ "", "x", "base" }, "", ""), CXX);
long_new->addVersion((void*)longNew<CAPI>, UNKNOWN, CAPI);
long_cls->giveAttr("__new__", new BoxedFunction(long_new, { boxInt(0), NULL }));
long_cls->giveAttr("__new__", new BoxedFunction(long_new, { NULL, NULL }));
long_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)longMul, UNKNOWN, 2)));
long_cls->giveAttr("__rmul__", long_cls->getattr(internStringMortal("__mul__")));
......
......@@ -37,11 +37,14 @@ print type(F2(D(F())))
print type(float(F()))
try:
f = float("hello world")
print f
except ValueError as e:
print e
for a in ["hello world", None]:
try:
f = float(a)
print f
except ValueError as e:
print "ValueError", e
except TypeError as e:
print "TypeError", e
try:
f = float("5 hello world")
......
......@@ -125,11 +125,11 @@ print type(+long.__new__(C, 5L))
print((0L).bit_length())
values = ['inf', '-inf', 'nan']
values = [float('inf'), float('-inf'), float('nan'), None]
for v in values:
try:
long(float(v))
long(v)
except Exception as e:
print(e.message)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment