[issue38001] Unexpected behaviour of 'is' operator

2019-09-01 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

Further to Karthikeyan Singaravelan comment, the behaviour you see is 
absolutely correct. The operator isn't behaving differently, it is reporting 
precisely the truth.

The ``is`` operator tests for object identity, not equality. Python makes no 
promises about object identity of literals. If you use an immutable literal in 
two places:

a = 1234
b = 1234

the interpreter is free to use the same object for both a and b, or different 
objects. The only promise made is that ``a == b``.

The Python interpreter currently caches some small integers for re-use, but 
that's not a language guarantee, and is subject to change without warning. It 
has changed in the past, and could change again in the future.

The bottom line is that you shouldn't use ``is`` except to test for object 
identity, e.g. ``if obj is None``.

--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38001] Unexpected behaviour of 'is' operator

2019-09-01 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38001] Unexpected behaviour of 'is' operator

2019-09-01 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

This will emit a SyntaxWarning in Python 3.8 to use == instead of using is for 
literals. This is not a bug but an implementation detail over caching a range 
of integers at 
https://github.com/python/cpython/blob/1f21eaa15e8a0d2b0f78d0e3f2b9e5b458eb0a70/Objects/longobject.c#L19

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38001] Unexpected behaviour of 'is' operator

2019-09-01 Thread Digin Antony


New submission from Digin Antony :

The 'is' operator behave differently on two sets of values 
please find the attachment below

tested environment 
windows 7
python 3.7.3


Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> a=256
>>> b=256
>>> a is b
True
>>> a=257
>>> b=257
>>> a is b
False

--
components: Interpreter Core
files: bug.png
messages: 350952
nosy: Digin Antony
priority: normal
severity: normal
status: open
title: Unexpected behaviour of  'is'  operator
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48578/bug.png

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com