New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[py3k] Integer floor division (//): small int check omitted #46669
Comments
Python 3.0a3 (r30a3:61161, Mar 1 2008, 22:51:17) [MSC v.1500 32 bit >>> a,b=1,1//1
>>> a is b
False
IDLE 3.0a3
>>> a,b=1,1//1
>>> a is b
True ditto for 2.5.2 interpreter On c.l.p, Duncan Booth wrote That maybe explains the change from 2.5 but not the difference from
IDLE. More important, the small int checks are present with the other
operations:
>>> 1*1 is 1
True
>>> 1+1 is 2
True
>>> 1-1 is 0
True
>>> 1**1 is 1
True so the omission with // is plausibly a bug. |
I agree this is a bug. Here is a related problem: >>> 1 is divmod(1,1)[0]
False |
>>> int('1') is 1
False
>>> 1 is int('0b1', 2)
False
>>> 1 is 0b10000 >> 4
False there are probably more ... |
>>> 1 is 1|1
False
>>> 1 is 1&1
False
>>> 0 is 1^1
False
>>> 2 is 1<<1
False |
I really don't understand *why* it's a bug. Is anywhere in the Language Reference that says that 1 should be the Or do you mean that they *should* be the same object for speed and/or |
The original bug is not whether or not python reuses int objects, but The later cases where the optimization is simply gone in 3.0a3 are more |
I agree that this is not a bug in the strict sense. I could have If the precise change is intentional, this should be documented (here) |
Attached patch fixes the cases discovered so far. It is possible that Any advise on how to write a unit test? Should the unit test detect |
Unless someone has a legitimate use case for disabling small_int that |
Attached (issue2417a.diff) patch adds unit tests and fixes a few corner |
Alexander, tried the issue2417a.diff patch against 65210, and does not Thanks! |
It looks like e-mail submission did not work. Uploading updated patch as issue2417b.diff . |
Commited in r65220. Thank you everybody!! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: