From 3a5c5475b5c2043dbe6791d3a5100a45d491546e Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Wed, 17 Apr 2013 00:04:46 -0600 Subject: 2to3: Apply unicode fixer. The unicode fixer strips the u from u'hi' and converts the unicode type to str. The first won't work for Python 2 and instead we replace the u prefix with the sixu function borrowed from the six compatibility package. That function calls the unicode constructor with the 'unicode_escape' encoder so that the many tests using escaped unicode characters like u'\u0900' will be handled correctly. That makes the sixu function a bit different from the asunicode function currently in numpy.compat and also provides a target that can be converted back to the u prefix when support for Python 3.2 is dropped. Python 3.3 reintroduced the u prefix for compatibility. The unicode fixer also replaces 'unicode' with 'str' as 'unicode' is no longer a builtin in Python 3. For code compatibility, 'unicode' is defined either as 'str' or 'unicode' in numpy.compat so that checks like if isinstance(x, unicode): ... will work properly for all python versions. Closes #3089. --- doc/sphinxext/numpydoc/docscrape_sphinx.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'doc/sphinxext/numpydoc/docscrape_sphinx.py') diff --git a/doc/sphinxext/numpydoc/docscrape_sphinx.py b/doc/sphinxext/numpydoc/docscrape_sphinx.py index d202bad34..a01d5d53f 100644 --- a/doc/sphinxext/numpydoc/docscrape_sphinx.py +++ b/doc/sphinxext/numpydoc/docscrape_sphinx.py @@ -1,10 +1,16 @@ from __future__ import division, absolute_import, print_function -import re, inspect, textwrap, pydoc +import re, inspect, textwrap, pydoc, aya import sphinx import collections from .docscrape import NumpyDocString, FunctionDoc, ClassDoc +if sys.version_info[0] >= 3: + sixu = lambda s: s +else: + sixu = lambda s: unicode(s, 'unicode_escape') + + class SphinxDocString(NumpyDocString): def __init__(self, docstring, config={}): self.use_plots = config.get('use_plots', False) @@ -95,11 +101,11 @@ class SphinxDocString(NumpyDocString): if others: maxlen_0 = max(3, max([len(x[0]) for x in others])) - hdr = u"="*maxlen_0 + u" " + u"="*10 - fmt = u'%%%ds %%s ' % (maxlen_0,) + hdr = sixu("=")*maxlen_0 + sixu(" ") + sixu("=")*10 + fmt = sixu('%%%ds %%s ') % (maxlen_0,) out += ['', hdr] for param, param_type, desc in others: - desc = u" ".join(x.strip() for x in desc).strip() + desc = sixu(" ").join(x.strip() for x in desc).strip() if param_type: desc = "(%s) %s" % (param_type, desc) out += [fmt % (param.strip(), desc)] -- cgit v1.2.1