RestrictType

class ipkiss3.all.RestrictType(allowed_types, **kwargs)

restrict the type or types the argument can have. Pass a type or tuple of types

Parameters
allowed_types: list or tuple

A tuple or list of types, the value assigned to the property should be an instance of one of those types.

Examples

from ipkiss.all import *

class Example(StrongPropertyInitializer):

    num_prop = DefinitionProperty(restriction=RestrictType((int, float)))

example1 = Example(num_prop=1.0) # this is ok
example2 = Example(num_prop=1) # this is ok as well
example3 = Example(num_prop="str") # this will fail
allowed_types
validate(value, obj=None)