types.py 文件源码

python
阅读 40 收藏 0 点赞 0 评论 0

项目:ronin 作者: tliron 项目源码 文件源码
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))))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号