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.

Unsupported provider

classification
Title: str(ImportError(b'foo')) fails
Type: behavior Stage: resolved
Components: Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, brian.curtin, dmalcolm, pitrou, python-dev
Priority: normal Keywords: patch

Created on 2012-08-24 16:38 by dmalcolm, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix-str-of-bogus-ImportError.patch dmalcolm, 2012-08-24 16:46 review
Messages (5)
msg169042 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2012-08-24 16:38
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.
msg169043 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-08-24 16:41
> This appears to be due to commit 76272.

Could you give the changeset id? Revision numbers are not portable from one repository clone to another.
msg169045 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2012-08-24 16:46
Sorry, it's 6825fd9b00ed
msg169048 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2012-08-24 16:52
(patch added)
msg169051 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-08-24 17:08
New changeset 91909962d7f5 by Brett Cannon in branch 'default':
Issue #15778: Coerce ImportError.args to a string when it isn't
http://hg.python.org/cpython/rev/91909962d7f5
History
Date User Action Args
2022-04-11 14:57:35adminsetgithub: 59982
2012-08-24 17:08:51brett.cannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2012-08-24 17:08:34python-devsetnosy: + python-dev
messages: + msg169051
2012-08-24 17:00:57brett.cannonsetassignee: brett.cannon
2012-08-24 16:59:34brett.cannonsetnosy: + brian.curtin
2012-08-24 16:52:01dmalcolmsetmessages: + msg169048
stage: patch review
2012-08-24 16:46:55dmalcolmsetfiles: + fix-str-of-bogus-ImportError.patch
keywords: + patch
2012-08-24 16:46:20dmalcolmsetmessages: + msg169045
2012-08-24 16:41:53pitrousetnosy: + pitrou
messages: + msg169043
2012-08-24 16:38:44dmalcolmcreate