use `if not isinstance(key, basestring)` to make it unicode proof.