[ python-Bugs-1748292 ] str.join() intercepts UnicodeDecodeError raised by iterator

SourceForge.net noreply at sourceforge.net
Thu Jul 5 14:26:57 CEST 2007


Bugs item #1748292, was opened at 2007-07-05 12:10
Message generated for change (Settings changed) made by lemburg
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1748292&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Unicode
Group: Python 2.5
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Christoph Zwerschke (cito)
Assigned to: M.-A. Lemburg (lemburg)
Summary: str.join() intercepts UnicodeDecodeError raised by iterator

Initial Comment:
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


----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2007-07-05 13:07

Message:
Logged In: YES 
user_id=89016
Originator: NO

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()


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1748292&group_id=5470


More information about the Python-bugs-list mailing list