jstraitlets.py 文件源码

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

项目:schemapi 作者: altair-viz 项目源码 文件源码
def _validate_numeric(trait, obj, value,
                      minimum=undefined, maximum=undefined,
                      exclusiveMinimum=undefined, exclusiveMaximum=undefined,
                      multipleOf=undefined, **extra_kwds):
    if value is None:
        return value

    if minimum is not undefined:
        exclusive = exclusiveMinimum is not undefined and exclusiveMinimum
        if value < minimum or (exclusive and value == minimum):
            raise T.TraitError(
                "The value of the '{name}' trait of {klass} instance should "
                "not be less than {min_bound}, but a value of {value} was "
                "specified".format(
                    name=trait.name, klass=class_of(obj),
                    value=value, min_bound=minimum))

    if maximum is not undefined:
        exclusive = exclusiveMaximum is not undefined and exclusiveMaximum
        if value > maximum or (exclusive and value == maximum):
            raise T.TraitError(
                "The value of the '{name}' trait of {klass} instance should "
                "not be greater than {max_bound}, but a value of {value} was "
                "specified".format(
                    name=trait.name, klass=class_of(obj),
                    value=value, max_bound=maximum))

    if multipleOf is not undefined:
        if value % multipleOf != 0:
            raise T.TraitError(
                "The value of the '{name}' trait of {klass} instance should "
                "be a multiple of {multiple}, but a value of {value} was "
                "specified".format(
                    name=trait.name, klass=class_of(obj),
                    value=value, multiple=multipleOf))
    return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号