Do you want this to use isinstance instead? It would make the logic a little more complicated to properly handle subclasses, but also might make it more general.