This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Incorrect Integer saving
Type: behavior Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti
Priority: normal Keywords:

Created on 2014-12-28 01:48 by Adam.Carruthers, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg233145 - (view) Author: Adam Carruthers (Adam.Carruthers) Date: 2014-12-28 01:48
255 is 255 -> True           (255).bit_length() -> 8
256 is 256 -> True           (256).bit_length() -> 9
257 is 257 -> False          (257).bit_length() -> 9
^
Will show True if you do it exactly like this because of a quirk.
a = 257
b = 257
a is b -> False

I think you don't want to map variables to integers direct unless they are at or under 8 bits in length.
msg233146 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2014-12-28 01:59
On CPython small ints are cached to improve performances.
This is an implementation detail and "is" should not be used to compare ints (== should be used instead).
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67313
2014-12-28 01:59:16ezio.melottisetstatus: open -> closed

type: enhancement -> behavior

nosy: + ezio.melotti
messages: + msg233146
resolution: not a bug
stage: resolved
2014-12-28 01:48:35Adam.Carrutherssetnosy: - Adam.Carruthers
-> (no value)
2014-12-28 01:48:19Adam.Carrutherscreate