# Check that the dimensionality of the source and target units match.
iftarget_unitisnotNone:
source=ureg(target_unit)
source=ureg_cached(target_unit)
source_dim=source.dimensionality
target=ureg(unit)
target=ureg_cached(unit)
target_dim=target.dimensionality
ifsource_dim!=target_dim:
raiseException("The dimensionality of unit '{}' does not match the dimensionality of unit '{}'. Cannot do the unit conversion.".format(unit,target_unit))