diff options
author | Pauli Virtanen <pav@iki.fi> | 2010-02-21 02:46:08 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-02-21 02:46:08 +0000 |
commit | 519fcca652d43ccbe31c0a7766ee1c7826dcad28 (patch) | |
tree | f8cc07fbca1d06737bb6187af3c549fa82b0ee69 | |
parent | e8a7df65457531e986a65483ffe79c98c7e811a8 (diff) | |
download | numpy-519fcca652d43ccbe31c0a7766ee1c7826dcad28.tar.gz |
3K: core/numerictypes: fix handling of Python types, and recognize bytes as a Python type
-rw-r--r-- | numpy/core/numerictypes.py | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 85de7f8b3..74b44fdab 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -99,10 +99,10 @@ import sys # we don't export these for import *, but we do want them accessible # as numerictypes.bool, etc. from __builtin__ import bool, int, long, float, complex, object, unicode, str +from numpy.compat import bytes if sys.version_info[0] >= 3: # Py3K - from builtins import bytes class long(int): # Placeholder class -- this will not escape outside numerictypes.py pass @@ -542,15 +542,23 @@ _python_types = {int : 'int_', float: 'float_', complex: 'complex_', bool: 'bool_', - str: 'string_', + bytes: 'bytes_', unicode: 'unicode_', buffer_type: 'void', } -def _python_type(t): - """returns the type corresponding to a certain Python type""" - if not isinstance(t, _types.TypeType): - t = type(t) - return allTypes[_python_types.get(t, 'object_')] + +if sys.version_info[0] >= 3: + def _python_type(t): + """returns the type corresponding to a certain Python type""" + if not isinstance(t, type): + t = type(t) + return allTypes[_python_types.get(t, 'object_')] +else: + def _python_type(t): + """returns the type corresponding to a certain Python type""" + if not isinstance(t, _types.TypeType): + t = type(t) + return allTypes[_python_types.get(t, 'object_')] def issctype(rep): """ |