From 4fbbf8c0a3c4b06853befc9f43e2fc5e80ccc197 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Tue, 25 Dec 2012 13:05:31 -0800 Subject: Fixes issue #16772: int() constructor second argument (base) must be an int. Consistent with the behavior in Python 2. --- Misc/NEWS | 3 +++ Objects/longobject.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 8da0d743..b85fd43 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1? Core and Builtins ----------------- +- Issue #16772: The int() constructor's second argument (base) no longer + accepts non integer values. Consistent with the behavior in Python 2. + - Issue #15422: Get rid of PyCFunction_New macro. Use PyCFunction_NewEx function (PyCFunction_New func is still present for backward compatibility). diff --git a/Objects/longobject.c b/Objects/longobject.c index 4024491..e4d4df4 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -4260,6 +4260,11 @@ long_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return PyLong_FromLong(0L); if (obase == NULL) return PyNumber_Long(x); + if (!PyLong_Check(obase)) { + PyErr_SetString(PyExc_TypeError, + "int() arg 2 must be an integer."); + return NULL; + } base = PyLong_AsLongAndOverflow(obase, &overflow); if (base == -1 && PyErr_Occurred()) -- cgit v0.12