`in` and `has_key` have different behavior for Unicode keys for `gdbm` in 2.7: ``` >>> import gdbm >>> db = gdbm.open("foo.gdbm","c") >>> db.has_key("a") 0 >>> db.has_key(u"a") 0 >>> "a" in db False >>> u"a" in db Traceback (most recent call last): File "", line 1, in TypeError: gdbm key must be string, not unicode ```
the problem is not present in Python 3.6.2 (default, Jul 17 2017, 16:44:45): ``` >>> import dbm >>> import dbm.gnu >>> db = dbm.gnu.open("foo","c") >>> "a" in db False >>> u"a" in db False ```
In python3, u"a" and "a" are the same thing. The equivalent in python3 would bee b"a" vs "a", but I have no idea if we even support bytes keys in python3 gdbm. In 2.7 does has_key(u"x") work if x is a valid key?
has_key(u"x") works if x is a valid key. has_key() parses the argument with PyArg_ParseTuple("s#") which implicitly converts unicode to str. __contains__() explicitly checks for str type.