4 <:type:>

<:type named_args:>

The <:type:> tag allows you to to run-time type checking on variables. Only keyword arguments are allowed. The <:type:> tag may appear anywhere in an STML document. The argument name is the name of the variable that you wish to check. The value is a Python expression that is either a type, a class, or a tuple of types and/or classes.

The named variables are then checked (in no particular order) to see if they pass an isinstance check with the value, or in the case where the value is a tuple, check to see if isinstance succeeds on any of the types/classes in the tuple. If there is no match, a TypeError will be raised.

Passing values other than classes or types is erroneous and will raise a TypeError at run-time. If a named variable doesn't exist, a NameError will be raised.

Some examples:

<:type x=`IntType` y=`StringType`:>
Check that x is an integer and that y is a string.

<:type foo=`(IntType, MyClass)`:>
Checks that foo is either an integer, or an instance of MyClass.

<:type foo=`y.__class__`:>
Checks to see that foo is an instance of the same class as y.