try to call __bytes__ before __index__ (closes #16722)

This commit is contained in:
Benjamin Peterson 2012-12-19 15:27:41 -06:00
parent 1f415cf2c2
commit 5ff3f73d94
3 changed files with 37 additions and 5 deletions

View file

@ -701,6 +701,12 @@ class BytesTest(BaseBytesTest):
def __bytes__(self):
return None
self.assertRaises(TypeError, bytes, A())
class A:
def __bytes__(self):
return b'a'
def __index__(self):
return 42
self.assertEqual(bytes(A()), b'a')
# Test PyBytes_FromFormat()
def test_from_format(self):