Use the more robust isinstance() rather than checking types directly