Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str.join() intercepts UnicodeDecodeError raised by iterator #45152

Closed
Cito mannequin opened this issue Jul 5, 2007 · 3 comments
Closed

str.join() intercepts UnicodeDecodeError raised by iterator #45152

Cito mannequin opened this issue Jul 5, 2007 · 3 comments
Assignees

Comments

@Cito
Copy link
Mannequin

Cito mannequin commented Jul 5, 2007

BPO 1748292
Nosy @malemburg, @doerwalter, @Cito

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/malemburg'
closed_at = <Date 2007-07-05.13:11:17.000>
created_at = <Date 2007-07-05.10:10:38.000>
labels = ['invalid', 'expert-unicode']
title = 'str.join() intercepts UnicodeDecodeError raised by iterator'
updated_at = <Date 2007-07-05.13:11:17.000>
user = 'https://github.com/Cito'

bugs.python.org fields:

activity = <Date 2007-07-05.13:11:17.000>
actor = 'cito'
assignee = 'lemburg'
closed = True
closed_date = None
closer = None
components = ['Unicode']
creation = <Date 2007-07-05.10:10:38.000>
creator = 'cito'
dependencies = []
files = []
hgrepos = []
issue_num = 1748292
keywords = []
message_count = 3.0
messages = ['32452', '32453', '32454']
nosy_count = 3.0
nosy_names = ['lemburg', 'doerwalter', 'cito']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1748292'
versions = ['Python 2.5']

@Cito
Copy link
Mannequin Author

Cito mannequin commented Jul 5, 2007

This is somewhat similar to bpo-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

@Cito Cito mannequin closed this as completed Jul 5, 2007
@Cito Cito mannequin added the invalid label Jul 5, 2007
@Cito Cito mannequin assigned malemburg Jul 5, 2007
@Cito Cito mannequin added the topic-unicode label Jul 5, 2007
@Cito Cito mannequin closed this as completed Jul 5, 2007
@Cito Cito mannequin added the invalid label Jul 5, 2007
@Cito Cito mannequin assigned malemburg Jul 5, 2007
@Cito Cito mannequin added the topic-unicode label Jul 5, 2007
@doerwalter
Copy link
Contributor

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

@Cito
Copy link
Mannequin Author

Cito mannequin commented Jul 5, 2007

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.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants