New submission from STINNER Victor <victor.stin...@haypocalc.com>:

With python3 -bb: {'key': 'value'}[b'key'] raises a BytesWarning, but {'key': 
'value'}[b'missing_key'] doesn't. The warning is unexpected here because it's 
an implicit comparaison (I mean, different than an explicit: 'key' == b'key'), 
we cannot check that the dict keys are all bytes / unicode (at least, I don't 
want to). And so I think that it should be fixed.

First lookdict_unicode() is used because all dict keys are unicode, but 
lookdict_unicode() falls back to lookdict() because the asked key type is not 
unicode.

lookdict() checks the hash: they matches, hash('key') == hash(b'key'). Then it 
compares the two key objects with PyObject_RichCompareBool(startkey, key, 
Py_EQ). PyUnicode_RichCompare() returns NotImplemented, and so 
bytes_richcompare() is called. Finally, bytes_richcompare() raises the 
BytesWarning.

----------
components: Interpreter Core, Unicode
messages: 114314
nosy: haypo
priority: normal
severity: normal
status: open
title: {'key': 'value'}[b'key'] raises a BytesWarning
versions: Python 3.2

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9636>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to