Skip to content

Conversation

@mdboom
Copy link
Contributor

@mdboom mdboom commented Aug 13, 2013

If a docstring is Unicode on Python 2.x, Numpydoc will crash with a UnicodeEncodeError. This is because it calls str on the SphinxDocString object, calling SphinxDocString.__str__ which returns unicode when the docstring itself is unicode. Python then fails converting that unicode object to a bytes (str) object using the default encoding.

# -*- coding: utf-8 -*-

docstring = u"""
numpydoc הוא מדהים
"""

from numpydoc import docscrape_sphinx

d = docscrape_sphinx.SphinxDocString(docstring)

x = str(d)  # fails
x = unicode(d)  # works, whether docstring is unicode or bytes

This PR restores the behavior in the numpydoc that ships with Numpy 1.7.1, which was to keep unicode as-is, and convert bytes to unicode using the default encoding.

@stefanv
Copy link
Contributor

stefanv commented Aug 14, 2013

+1

@jseabold
Copy link

+1

@mdboom
Copy link
Contributor Author

mdboom commented Oct 21, 2013

Any chance we can have this merged? As matplotlib has doctsrings with unicode, there have been a few reports over there about this.

certik added a commit that referenced this pull request Oct 21, 2013
Unicode docstrings are not handled correctly on Python 2.x
@certik certik merged commit 9fc0e08 into numpy:master Oct 21, 2013
pv pushed a commit that referenced this pull request Feb 14, 2015
ENH : simplify handling of Yield section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants