Raymond Hettinger <rhettin...@users.sourceforge.net> added the comment:
[Josh] > As in why does neither int.hex() or hex(float) work? I believe the answer to this is that Guido wanted hex() to be a purely integer concept. This was part of a broader effort relating to the __index__ magic method. The intent of that method is to be able to designate functions or methods as taking only integer arguments and flagging float arguments as errors. Indexing was a typical example where arr[3.1] would have gotten coerced to arr[3], possibly hiding an error in logic. The current situation represents a trade-off between parallel/consistent APIs across numeric types versus catching errors for integral functions that are erroneously fed a real valued argument. While I personally wished for the consistent API (i.e. hex() supporting ints and floats), in reality, I've found no real-world use cases where I needed to map a hexlifying function to mixed input containing both ints and floats. That suggests that the use cases are orthogonal and nothing was really lost by having two different APIs. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7028> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com