On 29 June 2010 03:48, Stefan Behnel <[email protected]> wrote:
> Lisandro Dalcin, 28.06.2010 22:52:
>> While porting petsc4py to work in Python 3, I noticed that __div__
>> special method is ignored. Should __truediv__ have __div__ as a
>> fallback ?
>
> -1, they're different things:
>
>   >>> class test(object):
>   ...   def __div__(a,b): return b
>   ...
>   >>> t = test()
>   >>> t / 2
>   2
>   >>> t // 2
>   Traceback (most recent call last):
>   TypeError: unsupported operand type(s) for //: 'test' and 'int'
>
> And I can't find a fixer in 2to3 either.
>
> What about a warning instead when __div__ is defined but __truediv__ is not?
>

OK, a warning would work. However, in Python 2, __truediv__ without
__div__ should also generate a warning; try your example with "from
__future__ import division", it will fail with TypeError. This is a
mess, still not sure what to do.



-- 
Lisandro Dalcin
---------------
CIMEC (INTEC/CONICET-UNL)
Predio CONICET-Santa Fe
Colectora RN 168 Km 472, Paraje El Pozo
Tel: +54-342-4511594 (ext 1011)
Tel/Fax: +54-342-4511169
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to