Robert wrote:
> According to the Python/C API, returning -1 from __hash__ is the way
> to signal an error. Of course, if one returns -1 manually one gets a
> runtime error that an error was raised without setting the exception.
> We could document this, but it's still kind of obscure.
>
> In Python one can do
>
> sage: class A:
> ....: def __hash__(self):
> ....: return int(-1)
> ....:
> sage: hash(A())
> -2
>
> Should we just check for -1 and return -2 for cdef class __hash__
> functions as well?
+1, but IMO it should wait until the rest of the operators have been
discussed for alignment with Python as well.
For instance I'd like to propose:
- Introduce "__cadd__" to take over for the current "__add__"
- Create a script which can convert source files (e.g. in Sage) and do
this change automatically (since the change below will slow things down)
- Make __cadd__ by default do something like this:
cdef class MyClass:
def __cadd__(a, b):
# body inserted if __add__ is implemented
if isinstance(a, MyClass):
return a.__add__(a, b)
else:
return b.__add__(b, a)
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev