Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e108373

Browse files
committed
It's ok for __hex__ or __oct__ to return unicode.
Don't insist that float('1'*10000) raises an exception.
1 parent a45ea58 commit e108373

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

Lib/test/test_builtin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,7 @@ def test_float(self):
608608
if have_unicode:
609609
self.assertEqual(float(str(" 3.14 ")), 3.14)
610610
self.assertEqual(float(str(b" \u0663.\u0661\u0664 ",'raw-unicode-escape')), 3.14)
611-
# Implementation limitation in PyFloat_FromString()
612-
self.assertRaises(ValueError, float, str("1"*10000))
611+
self.assertEqual(float("1"*10000), 1e10000) # Inf on both sides
613612

614613
@run_with_locale('LC_NUMERIC', 'fr_FR', 'de_DE')
615614
def test_float_with_comma(self):

Python/bltinmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ builtin_hex(PyObject *self, PyObject *v)
12301230
return NULL;
12311231
}
12321232
res = (*nb->nb_hex)(v);
1233-
if (res && !PyString_Check(res)) {
1233+
if (res && !PyString_Check(res) && !PyUnicode_Check(res)) {
12341234
PyErr_Format(PyExc_TypeError,
12351235
"__hex__ returned non-string (type %.200s)",
12361236
res->ob_type->tp_name);
@@ -1430,7 +1430,7 @@ builtin_oct(PyObject *self, PyObject *v)
14301430
return NULL;
14311431
}
14321432
res = (*nb->nb_oct)(v);
1433-
if (res && !PyString_Check(res)) {
1433+
if (res && !PyString_Check(res) && !PyUnicode_Check(res)) {
14341434
PyErr_Format(PyExc_TypeError,
14351435
"__oct__ returned non-string (type %.200s)",
14361436
res->ob_type->tp_name);

0 commit comments

Comments
 (0)