From 68338eed3ae91c9846142e088c16b63635e58178 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Sat, 13 Apr 2013 09:05:31 -0600 Subject: 2to3: Apply basestring fixer. The basestring class is not defined in Python 3 and the fixer replaces it with str. In order to have a common code base we define basestring in numpy/compat/py3k.py to be str when the Python version is >= 3, otherwise basestring and import it where needed. That works for most cases, but there are a few files where the version dependent define needs to be in the file. Closes #3042. --- numpy/lib/_iotools.py | 2 +- numpy/lib/format.py | 2 +- numpy/lib/npyio.py | 2 +- numpy/lib/recfunctions.py | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) (limited to 'numpy/lib') diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index dc143415e..4dedaadcd 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -8,13 +8,13 @@ __docformat__ = "restructuredtext en" import sys import numpy as np import numpy.core.numeric as nx +from numpy.compat import asbytes, bytes, asbytes_nested, long, basestring if sys.version_info[0] >= 3: from builtins import bool, int, float, complex, object, unicode, str else: from __builtin__ import bool, int, float, complex, object, unicode, str -from numpy.compat import asbytes, bytes, asbytes_nested, long if sys.version_info[0] >= 3: def _bytes_to_complex(s): diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 17f3463ad..40788e148 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -139,7 +139,7 @@ from __future__ import division, absolute_import, print_function import numpy import sys from numpy.lib.utils import safe_eval -from numpy.compat import asbytes, isfileobj, long +from numpy.compat import asbytes, isfileobj, long, basestring if sys.version_info[0] >= 3: import pickle diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index ea8d98656..4e8907c12 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -19,7 +19,7 @@ from ._iotools import LineSplitter, NameValidator, StringConverter, \ _is_string_like, has_nested_fields, flatten_dtype, \ easy_dtype, _bytes_to_name -from numpy.compat import asbytes, asstr, asbytes_nested, bytes +from numpy.compat import asbytes, asstr, asbytes_nested, bytes, basestring from io import BytesIO if sys.version_info[0] >= 3: diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py index 349d1996e..ffa5140bc 100644 --- a/numpy/lib/recfunctions.py +++ b/numpy/lib/recfunctions.py @@ -15,6 +15,7 @@ from numpy import ndarray, recarray from numpy.ma import MaskedArray from numpy.ma.mrecords import MaskedRecords from numpy.lib._iotools import _is_string_like +from numpy.compat import basestring if sys.version_info[0] >= 3: izip = zip -- cgit v1.2.1