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
Comments
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: 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, 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 |
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() |
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. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: