[Python-ideas] Warn about comparing bytes to int for `python3 -b`

Brett Cannon bcannon at gmail.com
Mon Mar 16 16:11:09 CET 2015


One of the rather subtle issues with writing Python 2/3 code is that
indexing on bytes in Python 2 returns a length-1 bytes object while in
Python 3 it returns an int. Because ==/!= always returns True/False it can
be a very subtle failure and tough to track down.

What do people think of extending -b/-bb in Python 3 to warn when
performing equality between an int and a bytes object of any length? I
don't want to restrict to length-1 bytes objects because people may be
doing comparisons where the result can be length-1 or any other length and
thus would still have a subtle bug to pick up. Do people think this would
raise a ton of false-positives? Would people find it useful?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150316/723cca66/attachment.html>


More information about the Python-ideas mailing list