New submission from Ethan Furman:

Using Enum to illustrate:

    --> class Grade(enum.Enum):
    ...   A = 4
    ...   B = 3
    ...   C = 2
    ...   D = 1
    ...   F = 0
    ...   def __index__(self):
    ...     return self._value_

    --> ['miserable'][Grade.F]
    'miserable'

    --> '%x' % Grade.F
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: %x format: a number is required, not Grade

    --> hex(Grade.F)
    '0x0'

I suggest that hex() and oct() have the same check that %x and %o do so that 
non-numbers are not representable as hex and octal.  

While we're at it, we should do the same for bin().  Are there any others?

I'll create a patch once we have a decision on which way to solve this issue.

----------
assignee: ethan.furman
messages: 206290
nosy: ethan.furman, gvanrossum, mark.dickinson, pitrou, rhettinger, 
serhiy.storchaka, skrah
priority: normal
severity: normal
status: open
title: hex() and %x, oct() and %o do not behave the same
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19995>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to