Is 'everything' a refrence or isn't it?

Bengt Richter bokr at oz.net
Mon Jan 16 16:18:35 EST 2006


On Mon, 16 Jan 2006 21:58:26 +1100, Steven D'Aprano <steve at REMOVETHIScyber.com.au> wrote:

>On Mon, 16 Jan 2006 10:34:40 +0000, Bengt Richter wrote:
>
>>  >>> class A:
>>  ...     def __getattr__(self, attr): print 'A().%s'%attr; raise AttributeError
>>  ...
>>  >>> class B:
>>  ...     def __getattr__(self, attr): print 'B().%s'%attr; raise AttributeError
>>  ...
>>  >>> A()==B()
>>  A().__eq__
>>  B().__eq__
>>  B().__eq__
>>  A().__eq__
>>  A().__coerce__
>>  B().__coerce__
>>  A().__cmp__
>>  B().__cmp__
>>  False
>
>Why are A().__eq__ and B().__eq__ both being called twice?
>
I imagine it's trying the calls with args swapped or something like that.
Want to write a test and see? (Don't hold your breath if you're waiting for me to do it ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list