For the latest batch of optimizations speeding up/replacing AstroPy unit operations in McFACTS (expect my next blog post titled The Agony and the Ecstasy of AstroPy Units), I've wound up just extracting the string representation of the unit type and matching on it directly:
