"More About Unicode in Python 2 and 3"

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Jan 5 17:56:27 EST 2014


Chris Angelico wrote:

> But this bit looks odd:
> 
> """
> For instance passing a urllib request object to Flask's JSON parse
> function breaks on Python 3 but works on Python 2 as a result of this:
> 
>>>> from urllib.request import urlopen
>>>> r = urlopen('https://pypi.python.org/pypi/Flask/json')
>>>> from flask import json
>>>> json.load(r)
> Traceback (most recent call last):
>   File "decoder.py", line 368, in raw_decode
> StopIteration
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: No JSON object could be decoded
> """

I'm not sure about the "works on Python 2" part. Is Armin just complaining
about the StopIteration being visible in Python 3 but hidden in Python 2? I
don't have Flask installed, and aren't going to install it just for this.


> Why is a StopIteration bubbling up? (I don't have Flask, so I can't
> verify this.) Is it as simple as "this should be raising from None",
> or is there something else going on?

Remember that "raise Spam from None" only works from Python 3.3 onwards.
Personally, I think that releasing nested tracebacks before having a way to
suppress the display was a strategic blunder, but it's fixed now, at least
for those who can jump straight to 3.3 and not bother supporting 3.1 and
3.2.


-- 
Steven




More information about the Python-list mailing list