diff -r ecf3cd3af502 Lib/test/test_int.py --- a/Lib/test/test_int.py Tue Dec 25 14:50:21 2012 -0800 +++ b/Lib/test/test_int.py Wed Dec 26 12:43:10 2012 +0200 @@ -321,9 +321,11 @@ def test_keyword_args(self): # Test invoking int() using keyword arguments. - self.assertEquals(int(x=1.2), 1) - self.assertEquals(int('100', base=2), 4) - self.assertEquals(int(x='100', base=2), 4) + self.assertEqual(int(x=1.2), 1) + self.assertEqual(int('100', base=2), 4) + self.assertEqual(int(x='100', base=2), 4) + self.assertRaises(TypeError, int, base=10) + self.assertRaises(TypeError, int, base=0) def test_valid_non_numeric_input_types_for_x(self): # Test possible valid non-numeric types for x, including subclasses @@ -356,18 +358,6 @@ 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.assertEquals(int(base=6), 0) - # Even invalid bases don't raise an exception. - self.assertEquals(int(base=1), 0) - self.assertEquals(int(base=1000), 0) def test_intconversion(self): # Test __int__() diff -r ecf3cd3af502 Lib/test/test_long.py --- a/Lib/test/test_long.py Tue Dec 25 14:50:21 2012 -0800 +++ b/Lib/test/test_long.py Wed Dec 26 12:43:10 2012 +0200 @@ -452,6 +452,13 @@ self.assertEqual(long('2br45qc', 35), 4294967297) self.assertEqual(long('1z141z5', 36), 4294967297) + def test_keyword_args(self): + # Test invoking long() using keyword arguments. + self.assertEqual(long(x=1.2), 1) + self.assertEqual(long('100', base=2), 4) + self.assertEqual(long(x='100', base=2), 4) + self.assertRaises(TypeError, long, base=10) + self.assertRaises(TypeError, long, base=0) def test_conversion(self): # Test __long__() diff -r ecf3cd3af502 Objects/intobject.c --- a/Objects/intobject.c Tue Dec 25 14:50:21 2012 -0800 +++ b/Objects/intobject.c Wed Dec 26 12:43:10 2012 +0200 @@ -1059,8 +1059,14 @@ 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)) { diff -r ecf3cd3af502 Objects/longobject.c --- a/Objects/longobject.c Tue Dec 25 14:50:21 2012 -0800 +++ b/Objects/longobject.c Wed Dec 26 12:43:10 2012 +0200 @@ -3987,8 +3987,14 @@ 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)) {