[Python-3000-checkins] r60090 - in python/branches/py3k: Lib/test/test_builtin.py Misc/NEWS Objects/longobject.c

facundo.batista python-3000-checkins at python.org
Sat Jan 19 20:12:02 CET 2008


Author: facundo.batista
Date: Sat Jan 19 20:12:01 2008
New Revision: 60090

Modified:
   python/branches/py3k/Lib/test/test_builtin.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Objects/longobject.c
Log:

Fix Issue #1769: Now int('- 1') or int('+ 1') is not allowed
any more.  Thanks Juan Jose Conti.  Also added tests.


Modified: python/branches/py3k/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k/Lib/test/test_builtin.py	(original)
+++ python/branches/py3k/Lib/test/test_builtin.py	Sat Jan 19 20:12:01 2008
@@ -49,7 +49,7 @@
     def write(self, line):
         pass
 
-L = [
+test_conv_no_sign = [
         ('0', 0),
         ('1', 1),
         ('9', 9),
@@ -71,6 +71,28 @@
         (chr(0x200), ValueError),
 ]
 
+test_conv_sign = [
+        ('0', 0),
+        ('1', 1),
+        ('9', 9),
+        ('10', 10),
+        ('99', 99),
+        ('100', 100),
+        ('314', 314),
+        (' 314', ValueError),
+        ('314 ', 314),
+        ('  \t\t  314  \t\t  ', ValueError),
+        (repr(sys.maxsize), sys.maxsize),
+        ('  1x', ValueError),
+        ('  1  ', ValueError),
+        ('  1\02  ', ValueError),
+        ('', ValueError),
+        (' ', ValueError),
+        ('  \t\t  ', ValueError),
+        (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314),
+        (chr(0x200), ValueError),
+]
+
 class TestFailingBool:
     def __bool__(self):
         raise RuntimeError
@@ -641,8 +663,18 @@
         # Different base:
         self.assertEqual(int("10",16), 16)
         # Test conversion from strings and various anomalies
-        for s, v in L:
-            for sign in "", "+", "-":
+        # Testing with no sign at front
+        for s, v in test_conv_no_sign:
+            for prefix in "", " ", "\t", "  \t\t  ":
+                ss = prefix + s
+                vv = v
+                try:
+                    self.assertEqual(int(ss), vv)
+                except v:
+                    pass
+        # No whitespaces allowed between + or - sign and the number
+        for s, v in test_conv_sign:
+            for sign in "+", "-":
                 for prefix in "", " ", "\t", "  \t\t  ":
                     ss = prefix + sign + s
                     vv = v

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Jan 19 20:12:01 2008
@@ -12,6 +12,8 @@
 Core and Builtins
 -----------------
 
+- Issue #1769: Now int("- 1") is not allowed any more.
+
 - Object/longobject.c: long(float('nan')) raises an OverflowError instead
   of returning 0.
 

Modified: python/branches/py3k/Objects/longobject.c
==============================================================================
--- python/branches/py3k/Objects/longobject.c	(original)
+++ python/branches/py3k/Objects/longobject.c	Sat Jan 19 20:12:01 2008
@@ -1685,8 +1685,6 @@
 		++str;
 		sign = -1;
 	}
-	while (*str != '\0' && isspace(Py_CHARMASK(*str)))
-		str++;
 	if (base == 0) {
 		if (str[0] != '0')
 			base = 10;


More information about the Python-3000-checkins mailing list