[Python-checkins] cpython: correctly lookup __trunc__ in int() constructor

benjamin.peterson python-checkins at python.org
Wed Mar 21 19:26:23 CET 2012


http://hg.python.org/cpython/rev/5a3af70180a2
changeset: 75854:5a3af70180a2
user: Benjamin Peterson <benjamin at python.org>
date: Tue Mar 20 23:48:11 2012 -0400
summary:
 correctly lookup __trunc__ in int() constructor
files:
 Lib/test/test_descr.py | 1 +
 Objects/abstract.c | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1770,6 +1770,7 @@
 ("__format__", format, format_impl, set(), {}),
 ("__floor__", math.floor, zero, set(), {}),
 ("__trunc__", math.trunc, zero, set(), {}),
+ ("__trunc__", int, zero, set(), {}),
 ("__ceil__", math.ceil, zero, set(), {}),
 ("__dir__", dir, empty_seq, set(), {}),
 ]
diff --git a/Objects/abstract.c b/Objects/abstract.c
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1350,7 +1350,7 @@
 }
 if (PyLong_Check(o)) /* An int subclass without nb_int */
 return _PyLong_Copy((PyLongObject *)o);
- trunc_func = _PyObject_GetAttrId(o, &PyId___trunc__);
+ trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__);
 if (trunc_func) {
 PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
 PyObject *int_instance;
@@ -1362,7 +1362,8 @@
 "__trunc__ returned non-Integral (type %.200s)");
 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))
 /* need to do extra error checking that PyLong_FromString()
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /