How can I create customized classes that have similar properties as 'str'?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Nov 24 17:19:38 EST 2007


On Sat, 24 Nov 2007 12:00:25 +0100, Bjoern Schliessmann wrote:

> Licheng Fang wrote:
>> I mean, all the class instances that equal to each other should be
>> reduced into only one instance, which means for instances of this class
>> there's no difference between a is b and a==b.
> 
> If you only want that if "a == b" is True also "a is b" is True,
> overload the is_ attribute of your class. Personally, I don't see any
> advantage in this.

No advantage? That's for sure. There is no is_ attribute of generic 
classes, and even if there was, it would have no special meaning.

Identity testing can't be overloaded. If it could, it would no longer be 
identity testing.


-- 
Steven.



More information about the Python-list mailing list