mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
bpo-29839: Raise ValueError rather than OverflowError in len() for negative values. (#701)
This commit is contained in:
parent
813f943c59
commit
baf9f29811
3 changed files with 24 additions and 6 deletions
|
@ -770,10 +770,18 @@ class BuiltinTest(unittest.TestCase):
|
|||
def __len__(self):
|
||||
return 4.5
|
||||
self.assertRaises(TypeError, len, FloatLen())
|
||||
class NegativeLen:
|
||||
def __len__(self):
|
||||
return -10
|
||||
self.assertRaises(ValueError, len, NegativeLen())
|
||||
class HugeLen:
|
||||
def __len__(self):
|
||||
return sys.maxsize + 1
|
||||
self.assertRaises(OverflowError, len, HugeLen())
|
||||
class HugeNegativeLen:
|
||||
def __len__(self):
|
||||
return -sys.maxsize-10
|
||||
self.assertRaises(ValueError, len, HugeNegativeLen())
|
||||
class NoLenMethod(object): pass
|
||||
self.assertRaises(TypeError, len, NoLenMethod())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue