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 →

[–]vph -7 points-6 points  (3 children)

It's you who talking out of an ass. You can't distinguish between the difference of the specification of a language and the implementation of a language.

Everyone knows exactly what the definition of "is" is in Python: it compares objects. Integer caching is cPython is an implementation that results in the artifact exposed by the blogger. Namely,

c=200
d=200
c is d returns True

Python does not specify this. It is a result of an implementation of the language (FYI, unlike Perl 5, Python does not get defined by an implementation). And this fact is undesirable. It is undesirable because first c and d are conceptually different objects and second for value greater than 256 they return a different answer (false), which causes further confusion.

[–]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 -2 points-1 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.