[issue19988] hex() and oct() use __index__ instead of __int__
Ethan Furman
report at bugs.python.org
Mon Dec 16 03:04:56 CET 2013
Ethan Furman added the comment:
For the record, the true/false values of my Logical type do convert to int, just not the unknown value.
I agree using __int__ is dubious because of float (and Decimal, etc.), which means really the only clean way to solve the issue (definitely for me, and for any one else in a similar situation) is to bring back __hex__, __oct__, and, presumably, __bin__.
To make things even worse, there is a discrepancy between hex() and %x, oct() and %o:
--> hex(Unknown)
'0x2'
--> oct(Unknown)
'0o2'
--> '%x' % Unknown
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %x format: a number is required, not Logical
--> '%o' % Unknown
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: %o format: a number is required, not Logical
Which is bizarre when one considers:
--> '%o' % Truth
'1'
So if '%o' fails, why doesn't oct()?
Do we reopen this issue, or start a new one?
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19988>
_______________________________________
More information about the Python-bugs-list
mailing list