On Fri, May 8, 2020 at 7:52 PM David Mertz <me...@gnosis.cx> wrote: > Me: For non-singleton immutables, identity is not really a meaningful >> thing. I mean, other than in a debugger or code profiler, or something >> special like that. I honestly do not know whether, e.g. '(1, "a", 3.5) is >> (1, "a", 3.5)'. I'll go try it, but I won't be sure the answer for every >> implementation, version, and even runtime, whether that answer will be >> consistent. >> > > So I did try it. I did not necessarily expect these particular results. > Moreover, I have a hunch that with PyPy JIT, something similar might > actually give different answers at different points when the same line was > encountered in a running interpreter. Not this example, but something else > that might cache values only later. > > I haven't done anything sneaky with the version at those paths. They are > all what the environment name hints they should be. PyPy is at 3.6, which > is the latest version on conda-forge. > > 810-tmp % $HOME/miniconda3/envs/py2.7/bin/python -c 'print((1, "a", 3.5) > is (1, "a", 3.5))' > False > 811-tmp % $HOME/miniconda3/envs/py3.4/bin/python -c 'print((1, "a", 3.5) > is (1, "a", 3.5))' > False > 812-tmp % $HOME/miniconda3/envs/py3.8/bin/python -c 'print((1, "a", 3.5) > is (1, "a", 3.5))' > <string>:1: SyntaxWarning: "is" with a literal. Did you mean "=="? > True > 813-tmp % $HOME/miniconda3/envs/pypy/bin/python -c 'print((1, "a", 3.5) is > (1, "a", 3.5))' > True > 814-tmp % $HOME/miniconda3/envs/py1/bin/python -c 'print (1, "a", 3.5) is > (1, "a", 3.5)' > 0 >
This is because of the peephole optimiser, right? ``` Python 3.8.0 (default, Oct 30 2019, 12:16:01) [GCC 7.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> (1, "a", 3.5) is (1, "a", 3.5) <stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="? True >>> x = (1, "a", 3.5) >>> x == (1, "a", 3.5) True >>> x is (1, "a", 3.5) <stdin>:1: SyntaxWarning: "is" with a literal. Did you mean "=="? False >>> ```
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/WPXU2FIV3DENWIPTPRESB7WWVMI6LJA3/ Code of Conduct: http://python.org/psf/codeofconduct/