mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Make subclasses of int, long, complex, float, and unicode perform type
conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald.
This commit is contained in:
parent
d7c795e729
commit
c3647ac93e
10 changed files with 326 additions and 76 deletions
|
|
@ -826,7 +826,10 @@ int_coerce(PyObject **pv, PyObject **pw)
|
|||
static PyObject *
|
||||
int_int(PyIntObject *v)
|
||||
{
|
||||
Py_INCREF(v);
|
||||
if (PyInt_CheckExact(v))
|
||||
Py_INCREF(v);
|
||||
else
|
||||
v = (PyIntObject *)PyInt_FromLong(v->ob_ival);
|
||||
return (PyObject *)v;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue