def verify_type(value, the_type):
"""
Raises :class:`TypeError` if the value is not an instance of the type.
:param value: value
:param the_type: type or type name
:type the_type: type|basestring
:raises TypeError: if ``value`` is not an instance of ``the_type``
:raises ~exceptions.ValueError: if ``the_type`` is invalid
:raises ImportError: if could not import the module
:raises AttributeError: if could not find the symbol in the module
"""
if isinstance(the_type, basestring):
the_type = import_symbol(the_type)
if not isclass(the_type):
raise ValueError(u'{} is not a type'.format(the_type))
if not isinstance(value, the_type):
raise TypeError(u'not an instance of {}: {}'.format(type_name(the_type),
type_name(type(value))))
评论列表
文章目录