Steven D'Aprano wrote:
On Fri, 06 Nov 2009 16:51:18 +0100, Marco Mariani wrote:

Using "x is y" with integers
makes no sense and has no guaranteed behaviour AFAIK

Of course it makes sense. `x is y` means *exactly the same thing* for ints as it does with any other object: it tests for object identity. That's all it does, and it does it perfectly.

Python makes no promise whether x = 3; y = 3 will use the same object for both x and y or not. That's an implementation detail. That's not a problem with `is`, it is a problem with developers who make unjustified assumptions.

Which is to say, it normally makes no sense to write 'm is n' for m, n ints.

The *exception* is when one is exploring implementation details, either to discover them or to test that they are as intended. So, last I looked, the test suite for ints makes such tests. If the implementation changes, the test should change also.

The problem comes when newbies use 'is' without realizing that they are doing black-box exploration of otherwise irrelevant internals. (White-box exploration would be reading the code, which makes it plain what is going on ;-).

Terry Jan Reedy


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to