[New-bugs-announce] [issue15778] str(ImportError(b'foo')) fails

Dave Malcolm report at bugs.python.org
Fri Aug 24 18:38:45 CEST 2012


New submission from Dave Malcolm:

In Python 3.2 and earlier:
>>> str(ImportError(b'foo'))
"b'foo'"

In Python 3.3:
>>> str(ImportError(b'foo'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __str__ returned non-string (type bytes)

This appears to be due to commit 76272.

I'm attaching a patch which fixes it, though perhaps ImportError should type-check the arguments

Motivation:
This leads to a failure of the test suite for "docutils" when run under Python 3.3 betas, specifically:

======================================================================
ERROR: test_unicode (test_error_reporting.ErrorStringTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/david/coding/python3.3/docutils/trunk/docutils/test3/test_error_reporting.py", line 154, in test_unicode
str(ErrorString(ImportError(self.bs))))
File "/home/david/coding/python3.3/docutils/trunk/docutils/build/lib/docutils/utils/error_reporting.py", line 124, in __str__
super(ErrorString, self).__str__())
File "/home/david/coding/python3.3/docutils/trunk/docutils/build/lib/docutils/utils/error_reporting.py", line 74, in __str__
return str(self.data)
TypeError: __str__ returned non-string (type bytes)

See http://docutils.svn.sourceforge.net/viewvc/docutils/trunk/docutils/test/test_error_reporting.py?revision=7464&view=markup for the test code.  Arguably docutils could just pick a different exception subclass.

----------
messages: 169042
nosy: brett.cannon, dmalcolm
priority: normal
severity: normal
status: open
title: str(ImportError(b'foo')) fails
type: behavior
versions: Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15778>
_______________________________________


More information about the New-bugs-announce mailing list