[Python-3000] Strange method resolution problem with __trunc__, __round__ on floats

Keir Mierle mierle at gmail.com
Fri Aug 24 02:23:47 CEST 2007


The newly introduced trunc() and round() have the following odd behavior:

$ ./python
Python 3.0x (py3k, Aug 23 2007, 17:15:22)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> trunc(3.14)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type float doesn't define __trunc__ method
[36040 refs]
>>> 3.14.__trunc__
<built-in method __trunc__ of float object at 0x8255244>
[36230 refs]
>>> trunc(3.14)
3
[36230 refs]
>>>

It looks like builtin_trunc() is failing at the call to
_PyType_Lookup(), which must be returning NULL to get the above
behavior. I'm not sure what's causing this; perhaps someone more
experienced than me has an idea?

Keir


More information about the Python-3000 mailing list