Serhiy Storchaka added the comment:

Here is a patches which contains only minimal set of required changes. Other 
unrelated changes will be done in issue16784.

----------
Added file: http://bugs.python.org/file28439/int_without_x-2.7_3.patch
Added file: http://bugs.python.org/file28440/int_without_x-3.2_3.patch
Added file: http://bugs.python.org/file28441/int_without_x-3.3_3.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16761>
_______________________________________
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)) {
diff -r e8793c5f0ebc Lib/test/test_int.py
--- a/Lib/test/test_int.py      Tue Dec 25 15:26:24 2012 -0800
+++ b/Lib/test/test_int.py      Wed Dec 26 12:43:18 2012 +0200
@@ -221,6 +221,14 @@
         self.assertEqual(int('2br45qc', 35), 4294967297)
         self.assertEqual(int('1z141z5', 36), 4294967297)
 
+    def test_keyword_args(self):
+        # Test invoking int() using keyword arguments.
+        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_intconversion(self):
         # Test __int__()
         class ClassicMissingMethods:
diff -r e8793c5f0ebc Objects/longobject.c
--- a/Objects/longobject.c      Tue Dec 25 15:26:24 2012 -0800
+++ b/Objects/longobject.c      Wed Dec 26 12:43:18 2012 +0200
@@ -4130,8 +4130,14 @@
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist,
                                      &x, &obase))
         return NULL;
-    if (x == NULL)
+    if (x == NULL) {
+        if (obase != NULL) {
+            PyErr_SetString(PyExc_TypeError,
+                            "int() missing string argument");
+            return NULL;
+        }
         return PyLong_FromLong(0L);
+    }
     if (obase == NULL)
         return PyNumber_Long(x);
 
@@ -4140,7 +4146,7 @@
         return NULL;
     if (overflow || (base != 0 && base < 2) || base > 36) {
         PyErr_SetString(PyExc_ValueError,
-                        "int() arg 2 must be >= 2 and <= 36");
+                        "int() base must be >= 2 and <= 36");
         return NULL;
     }
 
diff -r 517f3432d1b5 Lib/test/test_int.py
--- a/Lib/test/test_int.py      Tue Dec 25 15:27:56 2012 -0800
+++ b/Lib/test/test_int.py      Wed Dec 26 12:43:25 2012 +0200
@@ -226,19 +226,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)
-
-    # For example, PyPy 1.9.0 raised TypeError for these cases because it
-    # expects x to be a string if base is given.
-    @support.cpython_only
-    def test_base_arg_with_no_x_arg(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)
-        self.assertEquals(int(base='foo'), 0)
+        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_non_numeric_input_types(self):
         # Test possible non-numeric types for the argument x, including
diff -r 517f3432d1b5 Objects/longobject.c
--- a/Objects/longobject.c      Tue Dec 25 15:27:56 2012 -0800
+++ b/Objects/longobject.c      Wed Dec 26 12:43:25 2012 +0200
@@ -4267,8 +4267,14 @@
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:int", kwlist,
                                      &x, &obase))
         return NULL;
-    if (x == NULL)
+    if (x == NULL) {
+        if (obase != NULL) {
+            PyErr_SetString(PyExc_TypeError,
+                            "int() missing string argument");
+            return NULL;
+        }
         return PyLong_FromLong(0L);
+    }
     if (obase == NULL)
         return PyNumber_Long(x);
 
@@ -4277,7 +4283,7 @@
         return NULL;
     if (overflow || (base != 0 && base < 2) || base > 36) {
         PyErr_SetString(PyExc_ValueError,
-                        "int() arg 2 must be >= 2 and <= 36");
+                        "int() base must be >= 2 and <= 36");
         return NULL;
     }
 
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to