On Monday, 3 January 2022 18.32.14 WET José Abílio Matos wrote:
> In any case I found other cases where the code is wrong (like the BOM
> removal that does not work) and that it does not give an error although it
> is wrong.

For future reference this is an issue that happens silently. In this case 
Python's versatility comes to bite it.

Notice the following code:

line = "\357\273\277"
if line[0:3] == b"\357\273\277":
    print ("BOM found")

This could will give different results in Python 2 and 3.

The problem is that in Python 2 "\357\273\277" and b"\357\273\277" have the 
same type while in Python 3 they are different. That would not be a problem if 
it were not for another feature of Python, it is possible to compare different 
types and in that case the answer is naturally False.

The reason for this is to allow the comparison with None, that is usually used 
as sentinel in lots of code.

This bug is insidious because the code seems to work, there are no errors as 
those that led the original reporter to issue the proposed fix but the problem 
is there. :-(

As far as I understand the problem is specific to comparisons, since all the 
other operations will fail since we are using different types...
-- 
José Abílio
-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to