This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients vstinner
Date 2010-08-19.00:47:24
SpamBayes Score 2.1310784e-09
Marked as misclassified No
Message-id <1282178847.04.0.326162016951.issue9636@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-08-19 00:47:27vstinnersetrecipients: + vstinner
2010-08-19 00:47:27vstinnersetmessageid: <1282178847.04.0.326162016951.issue9636@psf.upfronthosting.co.za>
2010-08-19 00:47:25vstinnerlinkissue9636 messages
2010-08-19 00:47:24vstinnercreate