<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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,
                )