def _convert_to_and_validate_length_unit(unit, allow_dimensionless=False):
 try:
  unit = u.Unit(unit)
  assert (unit.is_equivalent(u.kpc) or (allow_dimensionless and (unit == u.dimensionless_unscaled)))
 except (TypeError, AssertionError):
  raise u.UnitsError(u'Unit "{0}" is not a length type'.format(unit))
 return unit

def _convert_to_and_validate_length_unit ( unit , allow_dimensionless = False ) : try : unit = u . Unit ( unit ) assert ( unit . is_equivalent ( u . kpc ) or ( allow_dimensionless and ( unit == u . dimensionless_unscaled ) ) ) except ( TypeError , AssertionError ) : raise u . UnitsError ( u'Unit "{0}" is not a length type' . format ( unit ) ) return unit
raises unitserror if not a length unit .