Dag Sverre Seljebotn wrote:

> In the ongoing fwrapification of SciPy [1], I'm getting regression test
> breakage because of this:
> 
> def func(float x):
>      return x
> 
>  >>> func(1 + 0j)
>      Traceback (most recent call last):
>      ...
>      TypeError: can't convert complex to float
> 
> 
> I'm wondering: Would people be OK to Cython so that when the imaginary
> part is *exactly* 0, it is OK to convert to native float? Or is failing
> hard the preferred behaviour?
> 
> (For all I know, SciPy may prefer to change their behaviour; so I'm just
> doing a poll for now.)
> 
> I guess the way to do it would be to try float conversion first, and if
> that fails, try complex conversion and see if the imaginary part ends up
> as 0. That is, it would mean that __complex__ would be called on passed
> in objects that do not support __float__ in the example above.
> 
> Dag Sverre
> 
> 
> [1]
> http://fortrancython.wordpress.com/2010/11/03/fwrap-to-be-used-by-scipy/

I prefer failing hard.  I believe that allowing complex to be used in place 
of float is a wart in numpy that leads to unintentional hidden mistakes.  If 
I want to take the real part I would say so.

The proposal to allow when im part is exactly zero is a horrible kluge.

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to