Josh Rosenberg <[email protected]> added the comment:
To be clear, this is a problem with old-style (printf-style) formatting, and
applies to both bytes formatting and str formatting. So a class like:
class Foo:
def __index__(self):
return 1
will fail with a TypeError should you do any of:
'%o' % Foo()
'%x' % Foo()
'%X' % Foo()
b'%o' % Foo()
b'%x' % Foo()
b'%X' % Foo()
even though hex(Foo()) and oct(Foo()) work without issue.
----------
title: Making a class formattable as hex/oct integer requires both __int__ and
__index__ for no good reason -> Making a class formattable as hex/oct integer
with printf-style formatting requires both __int__ and __index__ for no good
reason
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33002>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com