mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
bpo-34974: Do not replace unexpected errors in bytes() and bytearray(). (GH-9852)
bytes and bytearray constructors converted unexpected exceptions (e.g. MemoryError and KeyboardInterrupt) to TypeError.
This commit is contained in:
parent
de2aea0ff0
commit
e890421e33
4 changed files with 24 additions and 5 deletions
|
@ -126,8 +126,8 @@ class BaseBytesTest:
|
|||
a = self.type2test(b"\x01\x02\x03")
|
||||
self.assertEqual(a, b"\x01\x02\x03")
|
||||
|
||||
# http://bugs.python.org/issue29159
|
||||
# Fallback when __index__ raises exception other than OverflowError
|
||||
# Issues #29159 and #34974.
|
||||
# Fallback when __index__ raises a TypeError
|
||||
class B(bytes):
|
||||
def __index__(self):
|
||||
raise TypeError
|
||||
|
@ -184,6 +184,20 @@ class BaseBytesTest:
|
|||
except (OverflowError, MemoryError):
|
||||
pass
|
||||
|
||||
def test_constructor_exceptions(self):
|
||||
# Issue #34974: bytes and bytearray constructors replace unexpected
|
||||
# exceptions.
|
||||
class BadInt:
|
||||
def __index__(self):
|
||||
1/0
|
||||
self.assertRaises(ZeroDivisionError, self.type2test, BadInt())
|
||||
self.assertRaises(ZeroDivisionError, self.type2test, [BadInt()])
|
||||
|
||||
class BadIterable:
|
||||
def __iter__(self):
|
||||
1/0
|
||||
self.assertRaises(ZeroDivisionError, self.type2test, BadIterable())
|
||||
|
||||
def test_compare(self):
|
||||
b1 = self.type2test([1, 2, 3])
|
||||
b2 = self.type2test([1, 2, 3])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue