Message114314
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. |
|
Date |
User |
Action |
Args |
2010-08-19 00:47:27 | vstinner | set | recipients:
+ vstinner |
2010-08-19 00:47:27 | vstinner | set | messageid: <1282178847.04.0.326162016951.issue9636@psf.upfronthosting.co.za> |
2010-08-19 00:47:25 | vstinner | link | issue9636 messages |
2010-08-19 00:47:24 | vstinner | create | |
|