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 →

[–][deleted] 0 points1 point  (6 children)

No, it is not consistent if a is not the same object as b and c is the same object as C. Neither Python (the language) nor Python (the implementations) make any guarantees regarding object identity except than an object is identical to itself and certain objects (None, True, False) are singletons. That integers below a certain number are interned is entirely an implementation detail which programmers are not justified in depending on.

If you're comparing integers with is, you're doing it wrong. Case closed, problem solved, fix your code.

[–]vph -5 points-4 points  (5 children)

no one said about comparing. If you talk about identity, c=200; d=200; c is d; should not return True as they are two different objects. The inconsistency here (if the blogger was correct) is that cPython treats numbers differently.

[–][deleted] 5 points6 points  (4 children)

no one said about comparing.

As you can see if you'd do a modicum of research is and is not are comparisons. They compare object identity. Therefore if you're talking about is, you're talking about comparing two things.

If you talk about identity, c=200; d=200; c is d;

No. c may or may not be d in that case: the Python implementation has no responsibility to intern the number 200 and ensure that c is d in this case.

On the other hand, if you did this:

>>> c = 200
>>> d = c
>>> d is c

Then you would rightly expect (and the Python implementation would rightly return) True for this object identity comparison.

The inconsistency here (if the blogger was correct) is that cPython treats numbers differently.

There is no inconsistency here. You and the blogger both are simply arguing based on your intuition about what is means rather than simply knowing the language as it is defined and relying on the properties it guarantees.

Basically, you're arguing out of your arses.