def validate_type(arg_name, arg, valid_types):
if long_exists:
if valid_types is int:
valid_types = (int, long)
elif type(valid_types) is list and int in valid_types and long not in valid_types:
valid_types.append(long)
if type(valid_types) is list:
valid_types = tuple(valid_types)
if (type(valid_types) is type or # single type, not array of types
type(valid_types) is tuple or # several valid types as tuple
type(valid_types) is types.ClassType): # old style class
if isinstance(arg, valid_types):
return
raise STLTypeError(arg_name, type(arg), valid_types)
else:
raise STLError('validate_type: valid_types should be type or list or tuple of types')
# throws STLError if not exactly one argument is present
评论列表
文章目录