def coerce_value(cls, v):
        """Coerce a value to the right type for the collection, or return it if
        it is already of the right type."""
        if isinstance(v, cls.itemtype):
            return v
        else:
            try:
                return cls.coerceitem(v)
            except Exception as e:
                raise exc.CollectionItemCoerceError(
                    itemtype=cls.itemtype,
                    colltype=cls,
                    passed=v,
                    exc=e,
                )
Coerce a value to the right type for the collection, or return it if
        it is already of the right type.