This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients belopolsky, methane, serhiy.storchaka
Date 2018-10-13.19:18:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539458336.75.0.788709270274.issue34974@psf.upfronthosting.co.za>
In-reply-to
Content
bytes() and bytearray() replace some unexpected exceptions (including MemoryError and KeyboardInterrupt) with TypeError.

1) Exception in __index__.

class X:
    def __index__(self):
        raise MemoryError

`bytes(X())` results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot convert 'X' object to bytes

`bytearray(X())` results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'X' object is not iterable

This is related to issue29159.

2) Exception in __iter__.

class X:
    def __iter__(self):
        raise MemoryError

`bytes(X())` results in:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot convert 'X' object to bytes

`bytearray(X())` works correctly (raises a MemoryError).

The proper solution is to replace just a TypeError and allow other exceptions to emerge.
History
Date User Action Args
2018-10-13 19:18:56serhiy.storchakasetrecipients: + serhiy.storchaka, belopolsky, methane
2018-10-13 19:18:56serhiy.storchakasetmessageid: <1539458336.75.0.788709270274.issue34974@psf.upfronthosting.co.za>
2018-10-13 19:18:56serhiy.storchakalinkissue34974 messages
2018-10-13 19:18:56serhiy.storchakacreate