[Numpy-discussion] numpydoc for python 3?

Pierre Haessig pierre.haessig at crans.org
Mon Jan 14 06:04:57 EST 2013


Hi,

Le 14/01/2013 11:35, Jaakko Luttinen a écrit :
> Ok, thanks, maybe I'll try to make the tests valid in all Python
> versions. It seems there's only one line which I'm not able to transform.
>
> In doc/sphinxext/tests/test_docscrape.py, on line 559:
>     assert doc['Summary'][0] == u'öäöäöäöäöåååå'.encode('utf-8')
>
> This is invalid in Python 3.0-3.2. How could I write this in such a way
> that it is valid in all Python versions? I'm a bit lost with these
> unicode encodings in Python (and in general).. And I didn't want to add
> dependency on 'six' package.
Just as a side note about Python and encodings, I found great help in
watching (by chance) the PyCon 2012 presentation "Pragmatic Unicode or
How do I stop the Pain ?" by Ned Batchelder :
http://nedbatchelder.com/text/unipain.html

Now, if I understand the problem correctly, the u'xxx' syntax was
reintroduced in Python 3.3 specifically to enhance the 2to3
compatibility
(http://docs.python.org/3/whatsnew/3.3.html#pep-414-explicit-unicode-literals).
Maybe the question is then whether it's worth supporting Python 3.0-3.2
or not ?


Also, one possible rewrite of the test could be to replace the unicode
string with the corresponding utf8-encoded bytes :
assert doc['Summary'][0] ==
b'\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa4\xc3\xb6\xc3\xa5\xc3\xa5\xc3\xa5\xc3\xa5'
# output of 'öäöäöäöäöåååå'.encode('utf-8')
(One restriction : I think the b'' prefix was introduced in Python 2.6)

I'm not sure for the readability though...

Best,
Pierre



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130114/d565df29/attachment.sig>


More information about the NumPy-Discussion mailing list