The answer bytes == str is just False. That doesn't put b'' in your database by accident. It could be useful to separate the two kinds of warnings. On Fri, Jun 21, 2019, 18:57 Ivan Pozdeev via Python-Dev < python-dev@python.org> wrote:
On 22.06.2019 1:08, Daniel Holth wrote:
Thanks. I think I might like an option to disable str(bytes) without disabling str != bytes. Unless the second operation would also corrupt output.
You can't compare str to bytes without knowing the encoding the bytes are supposed to be in (see https://stackoverflow.com/questions/49991870/python-default-string-encoding for details).
And if you do know the encoding, you can as well compare `str.encode(encoding) != bytes` / `str != bytes.decode(encoding)`.
Came across this kind of set in the hyper http library which uses a set to accept certain headers with either str or bytes keys.
On Tue, Jun 18, 2019, 13:05 Christian Heimes <christian@python.org> wrote:
On 18/06/2019 18.32, Daniel Holth wrote:
set([u"foo", b"foo]) will error because the two kinds of string have the same hash, and this causes a comparison. Is that correct?
Yes, it will fail with -bb, because it turns comparison between str and bytes into an error. This can also happen with other strings when hash(u'somestring') & mask == hash(b'otherbytes') & mask. The mask of a set starts with PySet_MINSIZE - 1 == 8 and increases over team.
Christian
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/ZIF2MRBW...
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.orghttps://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/R6E7FAR3...
-- Regards, Ivan
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/XAN44UH5...