Kaydet (Commit) 1b1a8e7c authored tarafından Benjamin Peterson's avatar Benjamin Peterson

correctly lookup __trunc__ in int() constructor

üst 9fc9bf46
...@@ -1770,6 +1770,7 @@ order (MRO) for bases """ ...@@ -1770,6 +1770,7 @@ order (MRO) for bases """
("__format__", format, format_impl, set(), {}), ("__format__", format, format_impl, set(), {}),
("__floor__", math.floor, zero, set(), {}), ("__floor__", math.floor, zero, set(), {}),
("__trunc__", math.trunc, zero, set(), {}), ("__trunc__", math.trunc, zero, set(), {}),
("__trunc__", int, zero, set(), {}),
("__ceil__", math.ceil, zero, set(), {}), ("__ceil__", math.ceil, zero, set(), {}),
("__dir__", dir, empty_seq, set(), {}), ("__dir__", dir, empty_seq, set(), {}),
] ]
......
...@@ -1350,7 +1350,7 @@ PyNumber_Long(PyObject *o) ...@@ -1350,7 +1350,7 @@ PyNumber_Long(PyObject *o)
} }
if (PyLong_Check(o)) /* An int subclass without nb_int */ if (PyLong_Check(o)) /* An int subclass without nb_int */
return _PyLong_Copy((PyLongObject *)o); return _PyLong_Copy((PyLongObject *)o);
trunc_func = _PyObject_GetAttrId(o, &PyId___trunc__); trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__);
if (trunc_func) { if (trunc_func) {
PyObject *truncated = PyEval_CallObject(trunc_func, NULL); PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
PyObject *int_instance; PyObject *int_instance;
...@@ -1362,7 +1362,8 @@ PyNumber_Long(PyObject *o) ...@@ -1362,7 +1362,8 @@ PyNumber_Long(PyObject *o)
"__trunc__ returned non-Integral (type %.200s)"); "__trunc__ returned non-Integral (type %.200s)");
return int_instance; return int_instance;
} }
PyErr_Clear(); /* It's not an error if o.__trunc__ doesn't exist. */ if (PyErr_Occurred())
return NULL;
if (PyBytes_Check(o)) if (PyBytes_Check(o))
/* need to do extra error checking that PyLong_FromString() /* need to do extra error checking that PyLong_FromString()
......
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