This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ethan.furman
Recipients ethan.furman
Date 2013-12-15.16:27:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1387124872.75.0.863849760572.issue19988@psf.upfronthosting.co.za>
In-reply-to
Content
In Py3k __hex__ and __oct__ were removed, and hex() and oct() switched to use __index__.

hex() and oct() should be using __int__ instead.

Having read through PEP 357 [1] I see that __index__ is /primarily/ concerned with allowing arbitrary objects to be used in slices, but will also allow Python to convert an object to an int "whenever it needs one".

The problem is that my dbf [2] module has a couple custom types (Logical and Quantum) that allow for ternary logic (False/True/Unknown).  As much as possible Logical is intended to be a drop in replacement for the bool type, but of course there are some differences:

  - internally 'unknown' is represented as None

  - attempts to get an int, float, complex, etc., numeric value
    on Unknown raises an Exception

  - attempts to get the numeric string value via __hex__ and
    __oct__ on Unknown raises an Exception

  - when Unknown is used as an index (via __index__), 2 is returned

The problem, of course, is that in Python 3 calling hex() and oct() on Unknown now succeeds when it should be raising an exception, and would be if __int__ were used instead of __index__.

In summary, if Python just switches to using __index__, there would be little point in having separate __int__ and __index__ methods.


[1] http://www.python.org/dev/peps/pep-0357
[2] https://pypi.python.org/pypi/dbf
History
Date User Action Args
2013-12-15 16:27:52ethan.furmansetrecipients: + ethan.furman
2013-12-15 16:27:52ethan.furmansetmessageid: <1387124872.75.0.863849760572.issue19988@psf.upfronthosting.co.za>
2013-12-15 16:27:52ethan.furmanlinkissue19988 messages
2013-12-15 16:27:51ethan.furmancreate