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.

classification
Title: str.join() intercepts UnicodeDecodeError raised by iterator
Type: Stage:
Components: Unicode Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: lemburg Nosy List: cito, doerwalter, lemburg
Priority: normal Keywords:

Created on 2007-07-05 10:10 by cito, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg32452 - (view) Author: Christoph Zwerschke (cito) * Date: 2007-07-05 10:10
This is somewhat similar to #905389 which has already been fixed.

If you run the following two lines,

def gen(): raise UnicodeDecodeError
''.join(gen())

then instead of UnicodeDecodeError, you get:
TypeError: function takes exactly 5 arguments (0 given)

I found this bug in Python 2.3.5, 2.4.4 and 2.5.1 on Windows and Linux.

The bug appears exactly for UnicodeDecodeError,
UnicodeEncodeError, UnicodeTranslateError; all other exceptions work as expected. You can verify this with the following program:

import exceptions

def gen(e): raise e

for e in dir(exceptions):
    e = getattr(exceptions, e)
    if type(e) != type(Exception):
        continue
    try:
        ''.join(gen(e))
    except BaseException, f:
        e = e.__name__
        f = f.__class__.__name__
        if e != f:
            print e, f
msg32453 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2007-07-05 11:07
This has nothing to do with str.join(). The following script raises the same exception:

def gen():
   raise UnicodeDecodeError()

gen()

The problem is exactly what the exception message states: the UnicodeDecodeError constructor expects five arguments. The following version raises the expected UnicodeDecodeError:

def gen():
   raise UnicodeDecodeError('ascii', 'bytes', 0, 1, 'ouch')
gen()
msg32454 - (view) Author: Christoph Zwerschke (cito) * Date: 2007-07-05 13:11
Thanks for the quick analysis. You're completely right, it has nothing to do with ''.join(). You get the same error if you simply

raise UnicodeDecodeError

which I think is a bit confusing nevertheless. I had naively assumed that you can instantiate every Exception with no or a single string argument only, so I did not consider this could be the cause. Sorry.
History
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45152
2007-07-05 10:10:38citocreate