[issue16772] int() accepts float number base

Mark Dickinson report at bugs.python.org
Fri Dec 28 10:33:10 CET 2012


Mark Dickinson added the comment:

I'd suggest leaving 3.2 and 3.3 as they are: the bug is fairly benign, but  fixing it could break existing code unnecessarily.  That's something that we should try hard not to do in a bugfix release.

As to PyNumber_AsSsize_t() used instead PyLong_AsLongAndOverflow(), I *do* think that in general interfaces for built-in functions and methods that accept an integer should be prepared to accept anything that has an __index__.  If we can find a way to do that with sane exception types / messages, so much the better.  (One common application of __index__-able types occurs when using NumPy, where it's easy to end up with instances of numpy.int32 or numpy.int64 instead of regular Python ints.)  I agree with Serhiy that ValueError is the appropriate exception for out-of-range values.

[A side-issue here is that the various PyLong_As* utility functions are a mess: some use __int__, some use __index__, etc.  I have some thoughts about how to fix this, but that's another issue.]

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16772>
_______________________________________


More information about the Python-bugs-list mailing list