False == 0 fails
See original GitHub issueRecipe: Consider the following seemingly-innocent program:
a = 3==4
print("yyyyy", a, 0, a==0)
Desired and expected output:
yyyyy False 0 True
This works as expected under real python from the command line. The corresponding javascript also works as expected. However…
Observed rapydscript behavior:
yyyyy false 0 false
This is 100% reproducible chez moi. I am using the latest rapydscript-ng, from a fresh git-pull. FWIW the old non-ng version exhibits the same misbehavior.
This is more important than it might seem. The example above is highly simplified, to facilitate debugging. The same issue affects more-complicated code in ways that are much harder to understand. This wastes significant amounts of programmer time.
This started out as BruceSherwood/glowscript#60 but is hereby pushed upstream.
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (10 by maintainers)
Top GitHub Comments
I’m going to spell it out one last time for anyone else reading this bug report.
There is only one possible reason to do
a == 0
when a is of unknown type, and that is to check its truthiness. You trying to move the goalposts notwithstanding.Using
a == 0
to check truthiness is wrong, because it fails when a is any of; None, empty list, empty tuple, empty set, empty dict, empty string, any user defined type with a__bool__
method.Your proposed solution, to use the javascript
==
operator instead of the===
operator is so stupid, it boggles the mind. You want to bring in all the infelicities of the JS == operator in order to enablea == 0
, which is a stupid thing to do in the first place. And here is a link that explicates some of the problems with the==
operator in JS. http://stackoverflow.com/questions/359494/does-it-matter-which-equals-operator-vs-i-use-in-javascript-comparisons@JohnDenker Dont bother replying (although I suspect you cannot resist) I have blocked you.
I agree that reading the language specifications is a good idea in situations like this.
Just recently I was reading https://docs.python.org/3.1/library/stdtypes.html#numeric-types-int-float-complex where the second sentence says: Booleans are a subtype of integers.
Python considers False == 0 to be a comparison between integers. Booleans inherit comparison from integers. They inherit a lot of other things, too; for example:
(1==1) + (2==2)
evaluates to 2.Calling it «wrong in python» does not make it so. Calling it «insane» and «idiotic» and «asinine» does not make it so.
If you wish to argue that booleans ought not be a subtype of integers, please argue with the folks at python.org, not with me.
Javascript arrives at the same destination via a different path, via automatic type conversions, as previously discussed. The automatic conversion of integers to booleans, and vice versa, is mandatory. It is not open to question.