f---ing typechecking

James Stroud jstroud at mbi.ucla.edu
Thu Feb 15 07:07:19 EST 2007


Steven D'Aprano wrote:
> On Wed, 14 Feb 2007 22:21:43 -0800, James Stroud wrote:
> 
>>> The user's expected behaviour for [1] + (1,) might be to return a list, or
>>> it might be to return a tuple. Since there is no obviously correct
>>> behaviour, the right thing to do is to refuse to guess.
>> I guess we differ on what is obvious. This seems obvious to me:
>>
>> [1] + (1,) => [1, 1]
>> (1,) + [1] => (1, 1)
>>
>> simply becuase the operand on the left should take precendence because 
>> its "__add__" is called and its "__add__" returns a list.
> 
> But that's data dependent. When you call 
> 
> [1] + MyTuple(1)
> 
> your MyTuple.__radd__ will be called first, not the list's __add__.

OK. With this you are beginning to convince me. Yes, I would want my 
__radd__ called in this case (which is a form of mind-reading, but 
necessary and convenient)--so your point is how might python read one's 
mind given list and tuple. You got me there.

But you must agree that I am not an easy turn.



More information about the Python-list mailing list