Improve string type testing in Python 2.x versions