[Python-checkins] r69452 - in python/branches/release30-maint: Lib/test/test_builtin.py Misc/NEWS Objects/typeobject.c
benjamin.peterson
python-checkins at python.org
Sun Feb 8 22:16:02 CET 2009
Author: benjamin.peterson
Date: Sun Feb 8 22:16:01 2009
New Revision: 69452
Log:
Merged revisions 69451 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r69451 | benjamin.peterson | 2009年02月08日 15:07:20 -0600 (2009年2月08日) | 1 line
fix len() when __len__() returns a non number type #5137
........
Modified:
python/branches/release30-maint/ (props changed)
python/branches/release30-maint/Lib/test/test_builtin.py
python/branches/release30-maint/Misc/NEWS
python/branches/release30-maint/Objects/typeobject.c
Modified: python/branches/release30-maint/Lib/test/test_builtin.py
==============================================================================
--- python/branches/release30-maint/Lib/test/test_builtin.py (original)
+++ python/branches/release30-maint/Lib/test/test_builtin.py Sun Feb 8 22:16:01 2009
@@ -611,6 +611,18 @@
def __len__(self):
raise ValueError
self.assertRaises(ValueError, len, BadSeq())
+ class InvalidLen:
+ def __len__(self):
+ return None
+ self.assertRaises(TypeError, len, InvalidLen())
+ class FloatLen:
+ def __len__(self):
+ return 4.5
+ self.assertRaises(TypeError, len, FloatLen())
+ class HugeLen:
+ def __len__(self):
+ return sys.maxsize + 1
+ self.assertRaises(OverflowError, len, HugeLen())
def test_map(self):
self.assertEqual(
Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS (original)
+++ python/branches/release30-maint/Misc/NEWS Sun Feb 8 22:16:01 2009
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #5137: Make len() correctly raise a TypeError when a __len__ method
+ returns a non-number type.
+
- Issue #5182: Removed memoryview.__str__.
- Issue #1717: Removed builtin cmp() function, dropped tp_compare
Modified: python/branches/release30-maint/Objects/typeobject.c
==============================================================================
--- python/branches/release30-maint/Objects/typeobject.c (original)
+++ python/branches/release30-maint/Objects/typeobject.c Sun Feb 8 22:16:01 2009
@@ -4618,7 +4618,7 @@
if (res == NULL)
return -1;
- len = PyLong_AsSsize_t(res);
+ len = PyNumber_AsSsize_t(res, PyExc_OverflowError);
Py_DECREF(res);
if (len < 0) {
if (!PyErr_Occurred())
More information about the Python-checkins
mailing list