In Python 2.6 (and earlier) the hex()
and oct()
built-in functions can be overloaded in a class by defining __hex__
and __oct__
I think the short answer is 'No, bin()
can't be overloaded like oct()
and hex()
.'
As to why, the answer must lie with Python 3.0, which uses __index__
to overload hex()
, oct()
and bin()
, and has removed the __oct__
and __hex__
special functions altogether.
So the Python 2.6 bin()
looks very much like it's really a Python 3.0 feature that has been back-ported without much consideration that it's doing things the new Python 3 way rather than the old Python 2 way. I'd also guess that it's unlikely to get fixed, even if it is considered to be a bug.