Are dicts supposed to raise comparison errors

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Aug 2 03:20:38 EDT 2018


On Wed, 01 Aug 2018 22:14:54 +0300, Serhiy Storchaka wrote:

> 01.08.18 21:03, Chris Angelico пише:
>> And in any code that does not and cannot run on Python 2, the warning
>> about bytes and text comparing unequal is nothing more than a false
>> positive.
> 
> Not always. If your code supported Python 2 in the past, or third-party
> dependencies supports or supported Python 2, this warning can expose a
> real bug. Even if all your and third-party code always was Python 3
> only, the standard library can contain such kind of bugs.
> 
> Several years after the EOL of Python 2.7 and moving all living code to
> Python 3 we can ignore bytes warnings as always false positive.

Even then, I don't know that we should do that. I do not believe that the 
EOL of Python 2 will end all confusion between byte strings and text 
strings. There is ample opportunity for code to accidentally compare 
bytes and text even in pure Python 3 code, e.g. comparing data read from 
files reading from files which are supposed to be opened in the same 
binary/text mode but aren't.


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list