Page 1 of 1

False / True / O / 1 not equals !!!

Posted: Mon Jul 20, 2020 4:30 am
by JacquesC
Hello,
Does somebody have an idea to explain that :

There is an embarrassing difference beetween Python and microPython :

Code: Select all

MicroPython v1.12-120-g4ab8bee82 on 2020-02-02; ESP32 module with ESP32
>>> False == 0
False
>>> True == 1
False
========= and ==========

Code: Select all

Python 3.7.2 (/usr/local/bin/python3.7)
>>> False == 0
True
>>> True == 1
True
===================
In the same way :? :

Code: Select all

MicroPython v1.12-120-g4ab8bee82 on 2020-02-02; ESP32 module with ESP32
>>> a = False
>>> if a :
    print ("Not nul or True")
else :
    print("Nul or False")
    
Nul or False
>>> a = 0
>>> if a :
    print ("Not nul or True")
else :
    print("Nul or False")
    
Nul or False
>>> a == False
False
I think it is because the conditionnal expression if ... use int or boolean types to test if the expression is True/False or Null/not Null
but an int is not a boolean therefore 0 is not equal at False ...

Re: False / True / O / 1 not equals !!!

Posted: Mon Jul 20, 2020 7:00 am
by kevinkk525
I'd say this is a bug, not a difference. Probably an oversight during some changes last year to the comparator.

Re: False / True / O / 1 not equals !!!

Posted: Mon Jul 20, 2020 7:13 am
by jimmo
JacquesC wrote:
Mon Jul 20, 2020 4:30 am
Does somebody have an idea to explain that :
I think this was briefly an issue, introduced sometime after the v1.12 release and subsequently fixed. As Kevin mentioned, there were some changes to the way comparisons worked early this year that briefly caused some issues.

In v1.12 (built at the v1.12 tag)

Code: Select all

MicroPython v1.12 on 2020-07-20; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> False == 0
True
In the current latest version (current master branch)

Code: Select all

MicroPython v1.12-636-gdc73f9547-dirty on 2020-07-20; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> False == 0
True
I see you have "MicroPython v1.12-120-g4ab8bee82 on 2020-02-02;" which would be right about at the time that this was being worked on.

Re: False / True / O / 1 not equals !!!

Posted: Mon Jul 20, 2020 7:15 am
by jimmo

Re: False / True / O / 1 not equals !!!

Posted: Mon Jul 20, 2020 8:28 am
by JacquesC
Thank you Jimmo,
I am going to change my microPython version.