TypeMap Instances

The Teleport specification defines a mathematical function t, which maps type definitions to type instances. In Teleport, this mapping is performed by instances of TypeMap. These instances behave like functions and the t() function that you import from the teleport module is actually an instance of this class:


>>> from teleport import t
>>> t
<teleport.core.TypeMap at 0x7ffcb08e7c10>
class teleport.TypeMap
__call__(schema)

When you call the t() function, you are actually calling this method. You will rarely want to override this directly.

Parameters:schema – a JSON value
Returns:a Type instance
get_custom_type(name)

Override this method to enable dynamic type search. It gets called if the requested type is neither a core type nor a type added by register(). In that case, this is the last resort before Undefined is thrown.

Parameters:name – a string
Returns:a subclass of Type or None
register(name)

Used as a decorator to add a type to the type map.

@t.register("Truth")
class TruthType(ConcreteType):

    def check(self, value):
        return value is True