RestrictType

class ipkiss3.all.RestrictType

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.

Notes

Does not allow None values. Use i3.RestrictNone() | i3.RestrictType(allowed_types) to allow None.

Examples

import ipkiss3.all as i3

class Example(i3.StrongPropertyInitializer):

    num_prop = i3.DefinitionProperty(restriction=i3.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
example4 = Example(num_prop=None) # this will fail
allowed_types