[Python-checkins] cpython: Fixes issue #16772: int() constructor second argument (base) must be an int.

gregory.p.smith python-checkins at python.org
Tue Dec 25 22:05:42 CET 2012


http://hg.python.org/cpython/rev/e510e028c486
changeset:   81048:e510e028c486
parent:      81046:8ebbab768e1b
user:        Gregory P. Smith <greg at krypto.org>
date:        Tue Dec 25 13:05:31 2012 -0800
summary:
  Fixes issue #16772: int() constructor second argument (base) must be an int.
Consistent with the behavior in Python 2.

files:
  Misc/NEWS            |  3 +++
  Objects/longobject.c |  5 +++++
  2 files changed, 8 insertions(+), 0 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 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
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -4260,6 +4260,11 @@
         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())

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list