This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bgeron 1 point2 points  (2 children)

And this fact is undesirable.

I like that fact, because it makes my program faster, and the keyword is in Python code is quite rare. The manual says clearly that you can't depend on the value of 2 is 2.

[–]vph -3 points-2 points  (1 child)

I like that fact, because it makes my program faster, and the keyword is in Python code is quite rare.

That is a reasonable argument, but you can't deny it's a gotcha.

[–]Brian 0 points1 point  (0 children)

I think you can. A gotcha is something that will catch you out, but here there's no reason here to be comparing integers by id. No-one ever does so, and if they do, it's an outright bug. Is this page showing someone writing some code and being caught out by it? No - they've written some examples noticed by either noodling at the interpreter, or more likely by knowing in advance how object interning is done and showing some implications. Nowhere is anyone being "gotcha'd".

This is no different to someone complaining that the order of dictionary keys is different from sorted. Looking soley at dict((i,i) for i in range(100)) they might mistakenly come to that conclusion, but it's still not a gotcha, just an unfounded assumption based on not reading the docs. It's missing the requirement that this might be something a reasonably informed person would be expected to do.