Lisandro Dalcin, 29.06.2010 17:35: > On 29 June 2010 03:48, Stefan Behnel 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.
... certainly not the first time that I regret that Cython is following Python 2. Stefan _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
