Utility Classes :: Length
Overview
The Length() class is used when you don't care about the type of a sequence, or its contents, only its length.
The Length() constructor takes a single argument, the desired sequence length.
If the object being checked is not a sequence, or of the wrong length, things will blow up.
The following signature asserts that the sole parameter is a sequence -- regardless of type -- containing eight elements:
@accepts(Length(8))
Details
-
The
Length()constructor takes a single argument. If more or fewer arguments are provided, aTypeCheckErrorwill be raised.The value to this argument will be used to specify the length of a sequence, and accordingly needs to be something that can be passed to the built-in
int()function. -
If the object being checked does not define a
__len__method, a_TC_TypeErrorwill be raised.It is expected that this exception will be caught and converted to a
TypeCheckErrorbefore it reaches the user. -
If the sequence being checked is of the wrong length, a
_TC_LengthErrorwill be raised.It is expected that this exception will be caught and converted to a
TypeCheckErrorbefore it reaches the user. -
Lengthinstances that were created with the same length parameter will compare (==) as equals.All instances that compare equal will also hash to the same value.