Commits

Serhiy Storchaka committed 75eac27 Draft Merge

Merge heads

Comments (0)

Files changed (4)

Lib/test/test_int.py

         self.assertEqual(self.ntype(x=1.2), 1)
         self.assertEqual(self.ntype('100', base=2), 4)
         self.assertEqual(self.ntype(x='100', base=2), 4)
+        self.assertRaises(TypeError, self.ntype, base=10)
+        self.assertRaises(TypeError, self.ntype, base=0)
 
 class IntTestCases(IntLongCommonTests, unittest.TestCase):
 
 
     def test_error_on_string_base(self):
         self.assertRaises(TypeError, int, 100, base='foo')
-        # Include the following because in contrast CPython raises no error
-        # for bad integer bases when x is not given.
-        self.assertRaises(TypeError, int, base='foo')
-
-    # For example, PyPy 1.9.0 raised TypeError for these cases because it
-    # expects x to be a string if base is given.
-    @test_support.cpython_only
-    def test_int_base_without_x_returns_0(self):
-        self.assertEqual(int(base=6), 0)
-        # Even invalid bases don't raise an exception.
-        self.assertEqual(int(base=1), 0)
-        self.assertEqual(int(base=1000), 0)
 
     @test_support.cpython_only
     def test_small_ints(self):
 Core and Builtins
 -----------------
 
+- Issue #16761: Calling ``int()`` and ``long()`` with *base* argument only
+  now raises TypeError.
+
 - Issue #16759: Support the full DWORD (unsigned long) range in Reg2Py
   when retreiving a REG_DWORD value. This corrects functions like
   winreg.QueryValueEx that may have been returning truncated values.

Objects/intobject.c

     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:int", kwlist,
                                      &x, &base))
         return NULL;
-    if (x == NULL)
+    if (x == NULL) {
+        if (base != -909) {
+            PyErr_SetString(PyExc_TypeError,
+                            "int() missing string argument");
+            return NULL;
+        }
         return PyInt_FromLong(0L);
+    }
     if (base == -909)
         return PyNumber_Int(x);
     if (PyString_Check(x)) {

Objects/longobject.c

     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:long", kwlist,
                                      &x, &base))
         return NULL;
-    if (x == NULL)
+    if (x == NULL) {
+        if (base != -909) {
+            PyErr_SetString(PyExc_TypeError,
+                            "long() missing string argument");
+            return NULL;
+        }
         return PyLong_FromLong(0L);
+    }
     if (base == -909)
         return PyNumber_Long(x);
     else if (PyString_Check(x)) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.