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 vstinner
Recipients ethan.furman, python-dev, serhiy.storchaka, vstinner
Date 2015-04-03.08:48:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1428050920.88.0.0515749300504.issue23466@psf.upfronthosting.co.za>
In-reply-to
Content
> b'%c' is still raising a TypeError.  The error message is fine ("%c requires an integer in range(256) or a single byte") but it should be an OverflowError for backwards compatibility.

I don't understand why you care so much on the exact exception. It doesn't look right to me to rely on the *exact* exception raised by "%c" % arg. It's an obvious bug in the application.

Sometimes, you may want to be extra safe and catch exception while formating a message. The logging module does this. But the logging doesn't care of the exact exception, it uses a generic "except Except:" in StreamHandler.emit():

    def emit(self, record):
        try:
            msg = self.format(record)
            stream = self.stream
            stream.write(msg)
            stream.write(self.terminator)
            self.flush()
        except Exception:
            self.handleError(record)

IMO b"%c" % int must raise ValueError, not OverflowError, if the value is not in the range 0..255.
History
Date User Action Args
2015-04-03 08:48:40vstinnersetrecipients: + vstinner, ethan.furman, python-dev, serhiy.storchaka
2015-04-03 08:48:40vstinnersetmessageid: <1428050920.88.0.0515749300504.issue23466@psf.upfronthosting.co.za>
2015-04-03 08:48:40vstinnerlinkissue23466 messages
2015-04-03 08:48:40vstinnercreate