]> granicus.if.org Git - python/commitdiff
Issue 4842, patch 2/2: int('3L') should be invalid in Python 3.x.
authorMark Dickinson <dickinsm@gmail.com>
Tue, 20 Jan 2009 20:45:53 +0000 (20:45 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Tue, 20 Jan 2009 20:45:53 +0000 (20:45 +0000)
Lib/test/test_long.py
Misc/NEWS
Objects/longobject.c

index ed8c886cb36066dd21ec73c93c37a59a2d417a19..c1f8b5cbad8731d5602e06a2643cdb5d597e06de 100644 (file)
@@ -284,6 +284,16 @@ class LongTest(unittest.TestCase):
 
         self.assertRaises(ValueError, int, '123\0')
         self.assertRaises(ValueError, int, '53', 40)
+        # trailing L should no longer be accepted...
+        self.assertRaises(ValueError, int, '123L')
+        self.assertRaises(ValueError, int, '123l')
+        self.assertRaises(ValueError, int, '0L')
+        self.assertRaises(ValueError, int, '-37L')
+        self.assertRaises(ValueError, int, '0x32L', 16)
+        self.assertRaises(ValueError, int, '1L', 21)
+        # ... but it's just a normal digit if base >= 22
+        self.assertEqual(int('1L', 22), 43)
+
         self.assertRaises(TypeError, int, 1, 12)
 
         # SF patch #1638879: embedded NULs were not detected with
index d20d20b984d90209ac8684ac019a4f1d4228883c..9ffe6bee1bfb821af06e82ddfe338c4ce341b9c4 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.1 alpha 0
 Core and Builtins
 -----------------
 
+- Issue #4842: Don't allow trailing 'L' when constructing an integer
+  from a string.
+
 - Issue #4991: os.fdopen now raises an OSError for invalid file descriptors.
 
 - Issue #4838: When a module is deallocated, free the memory backing the
index b7ba7960ea0d1bc25d4b51f3ddb1ad37256852d7..46efe5f291e031c6367c3d7d777d21b6203382ea 100644 (file)
@@ -1990,8 +1990,6 @@ digit beyond the first.
                goto onError;
        if (sign < 0)
                Py_SIZE(z) = -(Py_SIZE(z));
-       if (*str == 'L' || *str == 'l')
-               str++;
        while (*str && isspace(Py_CHARMASK(*str)))
                str++;
        if (*str != '\0')