wtfpython icon indicating copy to clipboard operation
wtfpython copied to clipboard

Syntax error dependent on size of number

Open jneb opened this issue 2 years ago • 2 comments

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

jneb avatar Feb 03 '23 16:02 jneb

Hey @jneb , could you please write the explanation and make a PR? If it is possible, of course

nifadyev avatar Oct 16 '24 08:10 nifadyev

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...

jneb avatar Oct 16 '24 18:10 jneb