Issue 31398: TypeError: gdbm key must be string, not unicode (original) (raw)

Created on 2017-09-08 20:54 by sam-s, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg301728 - (view) Author: sds (sam-s) Date: 2017-09-08 20:54
`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 ```
msg301729 - (view) Author: sds (sam-s) Date: 2017-09-08 20:56
platform: Python 2.7.13 (default, Jul 18 2017, 09:17:00) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
msg301730 - (view) Author: sds (sam-s) Date: 2017-09-08 21:00
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 ```
msg301781 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-09-09 17:26
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?
msg301788 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-09 19:46
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.
msg396072 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-18 15:47
This seems like a python 2-only issue, if nobody objects I will close it in a couple of weeks.
msg396074 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-06-18 16:05
IMO you can close it immediately. Fixing Python 2.7 is not going to happen ever.
History
Date User Action Args
2022-04-11 14:58:52 admin set github: 75579
2021-06-18 16:23:29 iritkatriel set status: open -> closedstage: resolved
2021-06-18 16:05:51 vstinner set status: pending -> openmessages: +
2021-06-18 15:47:46 iritkatriel set status: open -> pendingnosy: + iritkatrielmessages: + resolution: out of date
2017-09-09 19:46:39 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2017-09-09 17:26:11 r.david.murray set nosy: + r.david.murraymessages: +
2017-09-08 21:00:21 sam-s set messages: +
2017-09-08 20:56:36 sam-s set messages: +
2017-09-08 20:54:57 sam-s create