2 # Copyright (C) 2007-2017 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 Ce module contient des fonctions utilitaires pour tester les types
25 from __future__ import absolute_import
33 # use isinstance() instead of type() because objects returned from numpy arrays
34 # inherit from python scalars but are numpy.float64 or numpy.int32...
38 return isinstance(obj, int) or type(obj) is int
42 return isinstance(obj, float)
46 return isinstance(obj, complex)
48 from decimal import Decimal
51 def isFloat_or_int(obj):
52 return isFloat(obj) or isInt(obj) or isinstance(obj, Decimal)
56 return isFloat_or_int(obj) or isComplex(obj)
60 return isinstance(obj, (str, six.text_type))
64 return type(obj) is list
68 return type(obj) is tuple
73 return type(obj) is _np_arr
77 """a sequence (allow iteration, not a string) ?"""
78 return isList(obj) or isTuple(obj) or isArray(obj)
82 from .N_ASSD import ASSD
83 return isinstance(obj, ASSD)
87 """Retourne `obj` si c'est une liste ou un tuple,
88 sinon retourne [obj,] (en tant que list).
90 if not isSequence(obj):
96 """Return `obj` as a tuple."""
97 return tuple(forceList(obj))
99 # backward compatibility
100 from warnings import warn
104 """same as isSequence"""
105 warn("'isEnum' is deprecated, use 'isSequence'",
106 DeprecationWarning, stacklevel=2)
107 return isSequence(obj)