summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2022-02-03 09:43:25 (GMT)
committerGitHub <noreply@github.com>2022-02-03 09:43:25 (GMT)
commitb4bd1e1422997de61faf506b4916e83013bc7d21 (patch)
treea6c3e97b10f04c4ca17f876c5c9cfa061d287a34 /Objects/abstract.c
parent7ffe7ba30fc051014977c6f393c51e57e71a6648 (diff)
downloadcpython-b4bd1e1422997de61faf506b4916e83013bc7d21.zip
cpython-b4bd1e1422997de61faf506b4916e83013bc7d21.tar.gz
cpython-b4bd1e1422997de61faf506b4916e83013bc7d21.tar.bz2
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.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 6a2d5ed..ed99fd6 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -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)) {