Skip to content

Commit d0875de

Browse files
committed
Towards fixing the Py2 bug in numpy#163
1 parent 9cd5944 commit d0875de

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

numpydoc/docscrape_sphinx.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pydoc
88
import collections
99
import os
10+
import locale
1011

1112
from jinja2 import FileSystemLoader
1213
from jinja2.sandbox import SandboxedEnvironment
@@ -146,6 +147,9 @@ def _process_param(self, param, desc, fake_autosummary):
146147
or inspect.isgetsetdescriptor(param_obj)):
147148
param_obj = None
148149
obj_doc = pydoc.getdoc(param_obj)
150+
if isinstance(obj_doc, bytes):
151+
# reverse the encoding performed in getdoc
152+
obj_doc = obj_doc.decode(locale.getpreferredencoding())
149153

150154
if not (param_obj and obj_doc):
151155
return display_param, desc

numpydoc/tests/test_docscrape.py

+21
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,27 @@ def test_unicode():
829829
assert isinstance(doc['Summary'][0], str)
830830
assert doc['Summary'][0] == 'öäöäöäöäöåååå'
831831

832+
class UnicodeProperty(object):
833+
"""Class with Attribute having its own non-ascii docstring
834+
835+
Attributes
836+
----------
837+
testattr : None
838+
Description here is overwritten
839+
testattr2 : None
840+
Description here is overwritten
841+
"""
842+
@property
843+
def testattr(self):
844+
"""öäöäöäöäöåååå"""
845+
846+
@property
847+
def testattr2(self):
848+
u"""öäöäöäöäöåååå"""
849+
850+
doc = SphinxClassDoc(UnicodeProperty)
851+
assert isinstance(str(doc), str)
852+
832853

833854
def test_plot_examples():
834855
cfg = dict(use_plots=True)

0 commit comments

Comments
 (0)