On 12/09/2010 03:08 PM, Robert Bradshaw wrote:
> On Thu, Dec 9, 2010 at 5:58 AM, Dag Sverre Seljebotn
> <da...@student.matnat.uio.no>  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.
>>      
> I'm -1 on making this change. If the author of the user class defined
> a __complex__ but not a __float__, we should respect that. Not to
> mention the added verbosity to the object ->  double path.
>    

How about a special case for the Python complex type? Still -1?

Dag Sverre
_______________________________________________
Cython-dev mailing list
Cython-dev@codespeak.net
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to