wtfpython
wtfpython copied to clipboard
Syntax error dependent on size of number
How about this one:
>>> 4 ** 300 == 8 ** 200
True
>>> 4 ** 300 is 8 ** 200
False
>>> 4 ** 30 is 8 ** 20
SyntaxWarning: "is" with a literal. Did you mean "=="?
4 ** 30 is 8 ** 20
True
Hey @jneb , could you please write the explanation and make a PR? If it is possible, of course
To be honest, I have no idea. I thought it had to do with the size of the left operand, but I'm flabbergasted by this: Just checking:
>>> (1<<128)-(1<<124) == 15<<124
True
Difference between two expressions with same value:
>>> 15<<124 is 8**300
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
>>> (1<<128)-(1<<124) is 8**300
False
But it's also not the form of the expression, because making it a bit smaller raises the warning again:
>>> (1<<127)-(1<<124) is 8**300
<stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="?
False
All I know is that there's something about the left operand. Smaller send to produce the warning, but there's more behind it. I'll have to check the source...