diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-03-25 10:11:43 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-03-25 10:36:28 +0000 |
commit | b87fca27261f79be20ab06a222ed2330d60d9f2c (patch) | |
tree | 00907ad5fffa7d13f99b1cf60398c624063f807e /numpy/core/_internal.py | |
parent | a2c4d3230d58a5c4569ab2c7f13bdf9499b71dd4 (diff) | |
download | numpy-b87fca27261f79be20ab06a222ed2330d60d9f2c.tar.gz |
MAINT: Remove asbytes where a b prefix would suffice
Since we only need to support python 2, we can remove any case where we just
pass a single string literal and use the b prefix instead.
What we can't do is transform asbytes("tests %d" % num), because %-formatting
fails on bytes in python 3.x < 3.5.
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r-- | numpy/core/_internal.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index d73cdcc55..11a13026b 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -9,15 +9,15 @@ from __future__ import division, absolute_import, print_function import re import sys -from numpy.compat import asbytes, basestring +from numpy.compat import basestring from .multiarray import dtype, array, ndarray import ctypes from .numerictypes import object_ if (sys.byteorder == 'little'): - _nbo = asbytes('<') + _nbo = b'<' else: - _nbo = asbytes('>') + _nbo = b'>' def _makenames_list(adict, align): allfields = [] @@ -136,17 +136,16 @@ def _reconstruct(subtype, shape, dtype): # format_re was originally from numarray by J. Todd Miller -format_re = re.compile(asbytes( - r'(?P<order1>[<>|=]?)' - r'(?P<repeats> *[(]?[ ,0-9L]*[)]? *)' - r'(?P<order2>[<>|=]?)' - r'(?P<dtype>[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)')) -sep_re = re.compile(asbytes(r'\s*,\s*')) -space_re = re.compile(asbytes(r'\s+$')) +format_re = re.compile(br'(?P<order1>[<>|=]?)' + br'(?P<repeats> *[(]?[ ,0-9L]*[)]? *)' + br'(?P<order2>[<>|=]?)' + br'(?P<dtype>[A-Za-z0-9.?]*(?:\[[a-zA-Z0-9,.]+\])?)') +sep_re = re.compile(br'\s*,\s*') +space_re = re.compile(br'\s+$') # astr is a string (perhaps comma separated) -_convorder = {asbytes('='): _nbo} +_convorder = {b'=': _nbo} def _commastring(astr): startindex = 0 @@ -171,9 +170,9 @@ def _commastring(astr): (len(result)+1, astr)) startindex = mo.end() - if order2 == asbytes(''): + if order2 == b'': order = order1 - elif order1 == asbytes(''): + elif order1 == b'': order = order2 else: order1 = _convorder.get(order1, order1) @@ -184,10 +183,10 @@ def _commastring(astr): (order1, order2)) order = order1 - if order in [asbytes('|'), asbytes('='), _nbo]: - order = asbytes('') + if order in [b'|', b'=', _nbo]: + order = b'' dtype = order + dtype - if (repeats == asbytes('')): + if (repeats == b''): newitem = dtype else: newitem = (dtype, eval(repeats)) |