[Python-Dev] PEP 208 and __coerce__
Neil Schemenauer
nas@arctrix.com
Sat, 9 Dec 2000 03:30:06 -0800
While working on the implementation of PEP 208, I discovered that
__coerce__ has some surprising properties. Initially I
implemented __coerce__ so that the numberic operation currently
being performed was called on the values returned by __coerce__.
This caused test_class to blow up due to code like this:
class Test:
def __coerce__(self, other):
return (self, other)
The 2.0 "solves" this by not calling __coerce__ again if the
objects returned by __coerce__ are instances. This has the
effect of making code like:
class A:
def __coerce__(self, other):
return B(), other
class B:
def __coerce__(self, other):
return 1, other
A() + 1
fail to work in the expected way. The question is: how should
__coerce__ work? One option is to leave it work the way it does
in 2.0. Alternatively, I could change it so that if coerce
returns (self, *) then __coerce__ is not called again.
Neil