2to3: Apply unicode fixer. #3257

Merged
merged 2 commits into from Apr 22, 2013

Projects

None yet

2 participants

@charris
Member
charris commented Apr 17, 2013

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.

@charris
Member
charris commented Apr 17, 2013

The 'sixu' name is open for suggested alternatives.

@pv pv and 1 other commented on an outdated diff Apr 17, 2013
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
@pv
pv Apr 17, 2013 Member

What's aya? Testing if someone reads this ?)

@charris
charris Apr 18, 2013 Member

Looks like a typo, I'd guess vim running in the wrong mode and the cursor in the wrong window, or some such. I'll fix it.

charris added some commits Apr 17, 2013
@charris charris 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.
3a5c547
@charris charris BUG: Fix typo in docscrape_sphinx.py import. 211154e
@charris
Member
charris commented Apr 22, 2013

Time for this to go in.

@charris charris merged commit ee19043 into numpy:master Apr 22, 2013

1 check passed

default The Travis build passed
Details
@charris charris deleted the charris:2to3-apply-unicode-fixer branch Apr 22, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment