[Python-checkins] bpo-34087: Backport tests for int/float/complex (GH-8274)

INADA Naoki webhook-mailer at python.org
Sat Jul 14 03:38:22 EDT 2018


https://github.com/python/cpython/commit/b2f8aa0c998d331ab2b4c701756a6427c0e91d48
commit: b2f8aa0c998d331ab2b4c701756a6427c0e91d48
branch: 3.6
author: INADA Naoki <methane at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018年07月14日T16:38:14+09:00
summary:
bpo-34087: Backport tests for int/float/complex (GH-8274)
Cherrypick tests from 16dfca4d829e45f36e71bf43f83226659ce49315
While the regression is not in 3.6, it's worth to backport test cases
to 3.6 branch too.
files:
M Lib/test/test_complex.py
M Lib/test/test_float.py
M Lib/test/test_long.py
M Python/pystrtod.c
diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py
index cee49343e268..1980fc409264 100644
--- a/Lib/test/test_complex.py
+++ b/Lib/test/test_complex.py
@@ -345,6 +345,9 @@ def split_zeros(x):
 self.assertEqual(type(complex("1"*500)), complex)
 # check whitespace processing
 self.assertEqual(complex('\N{EM SPACE}(\N{EN SPACE}1+1j ) '), 1+1j)
+ # Invalid unicode string
+ # See bpo-34087
+ self.assertRaises(ValueError, complex, '\u3053\u3093\u306b\u3061\u306f')
 
 class EvilExc(Exception):
 pass
diff --git a/Lib/test/test_float.py b/Lib/test/test_float.py
index c5ca50c8f712..61551e5c9903 100644
--- a/Lib/test/test_float.py
+++ b/Lib/test/test_float.py
@@ -60,6 +60,9 @@ def test_float(self):
 # extra long strings should not be a problem
 float(b'.' + b'1'*1000)
 float('.' + '1'*1000)
+ # Invalid unicode string
+ # See bpo-34087
+ self.assertRaises(ValueError, float, '\u3053\u3093\u306b\u3061\u306f')
 
 def test_underscores(self):
 for lit in VALID_UNDERSCORE_LITERALS:
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index fd15f04aceca..140ace18dd1e 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -373,6 +373,10 @@ def test_long(self):
 for base in invalid_bases:
 self.assertRaises(ValueError, int, '42', base)
 
+ # Invalid unicode string
+ # See bpo-34087
+ self.assertRaises(ValueError, int, '\u3053\u3093\u306b\u3061\u306f')
+
 
 def test_conversion(self):
 
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 64d0c52e4879..58278c24be9c 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -391,6 +391,8 @@ _Py_string_to_number_with_underscores(
 char *dup, *end;
 PyObject *result;
 
+ assert(s[orig_len] == '0円');
+
 if (strchr(s, '_') == NULL) {
 return innerfunc(s, orig_len, arg);
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /