Skip to content

v0.3.1 -- InstanceOf and SubclassOf

Compare
Choose a tag to compare
@mansam mansam released this 21 Jan 18:09
· 54 commits to master since this release

This update adds the InstanceOf and SubclassOf validators. True to their names, InstanceOf requires that a value be an instance of a base class or its subclasses, and SubclassOf requires that a value actually be a class that inherits from the specified class.

InstanceOf

# InstanceOf Example:
validations = {
    "field": [InstanceOf(basestring)]
}
passes = {"field": ""} # is a <'str'>, subclass of basestring
fails  = {"field": str} # is a <'type'

SubclassOf:

# SubclassOf Example
validations = {
    "field": [SubclassOf(basestring)]
}
passes = {"field": str} # is a subclass of basestring
fails  = {"field": int}

Thanks to @ryansb for the SubclassOf validator he submitted in #1.