mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-44977: Deprecate delegation of int to __trunc__ (GH-31031)
Calling int(a) when type(a) implements __trunc__ but not __int__ or __index__ now raises a DeprecationWarning.
This commit is contained in:
parent
7ffe7ba30f
commit
b4bd1e1422
8 changed files with 40 additions and 11 deletions
|
@ -1564,6 +1564,11 @@ PyNumber_Long(PyObject *o)
|
|||
}
|
||||
trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__);
|
||||
if (trunc_func) {
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"The delegation of int() to __trunc__ is deprecated.", 1)) {
|
||||
Py_DECREF(trunc_func);
|
||||
return NULL;
|
||||
}
|
||||
result = _PyObject_CallNoArgs(trunc_func);
|
||||
Py_DECREF(trunc_func);
|
||||
if (result == NULL || PyLong_CheckExact(result)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue